single_term_title

函式
single_term_title ( $prefix = '', $display = true )
引數
  • (string) $prefix Optional. What to display before the title.
    Required:
    Default: (empty)
  • (bool) $display Optional. Whether to display or retrieve title. Default true.
    Required:
    Default: true
返回值
  • (string|void) Title when retrieving.
定義位置
相關方法
single_cat_titlesingle_tag_titlesingle_post_titlesingle_month_titleget_the_title
引入
3.1.0
棄用
-

single_term_title:該函式用於顯示單個術語檔案頁的標題。它接受兩個引數 – $prefix 和 $display。$prefix引數是可選的,允許你為標題新增字首,而$display引數也是可選的,允許你控制標題是否顯示在螢幕上或作為字串返回。

顯示或檢索分類法術語檔案的頁面標題。

對分類術語模板檔案顯示分類術語頁面標題很有用。字首之間不會自動放置空格,所以如果應該有空格,引數值就需要在最後面有。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function single_term_title( $prefix = '', $display = true ) {
$term = get_queried_object();
if ( ! $term ) {
return;
}
if ( is_category() ) {
/**
* Filters the category archive page title.
*
* @since 2.0.10
*
* @param string $term_name Category name for archive being displayed.
*/
$term_name = apply_filters( 'single_cat_title', $term->name );
} elseif ( is_tag() ) {
/**
* Filters the tag archive page title.
*
* @since 2.3.0
*
* @param string $term_name Tag name for archive being displayed.
*/
$term_name = apply_filters( 'single_tag_title', $term->name );
} elseif ( is_tax() ) {
/**
* Filters the custom taxonomy archive page title.
*
* @since 3.1.0
*
* @param string $term_name Term name for archive being displayed.
*/
$term_name = apply_filters( 'single_term_title', $term->name );
} else {
return;
}
if ( empty( $term_name ) ) {
return;
}
if ( $display ) {
echo $prefix . $term_name;
} else {
return $prefix . $term_name;
}
}
function single_term_title( $prefix = '', $display = true ) { $term = get_queried_object(); if ( ! $term ) { return; } if ( is_category() ) { /** * Filters the category archive page title. * * @since 2.0.10 * * @param string $term_name Category name for archive being displayed. */ $term_name = apply_filters( 'single_cat_title', $term->name ); } elseif ( is_tag() ) { /** * Filters the tag archive page title. * * @since 2.3.0 * * @param string $term_name Tag name for archive being displayed. */ $term_name = apply_filters( 'single_tag_title', $term->name ); } elseif ( is_tax() ) { /** * Filters the custom taxonomy archive page title. * * @since 3.1.0 * * @param string $term_name Term name for archive being displayed. */ $term_name = apply_filters( 'single_term_title', $term->name ); } else { return; } if ( empty( $term_name ) ) { return; } if ( $display ) { echo $prefix . $term_name; } else { return $prefix . $term_name; } }
function single_term_title( $prefix = '', $display = true ) {
	$term = get_queried_object();

	if ( ! $term ) {
		return;
	}

	if ( is_category() ) {
		/**
		 * Filters the category archive page title.
		 *
		 * @since 2.0.10
		 *
		 * @param string $term_name Category name for archive being displayed.
		 */
		$term_name = apply_filters( 'single_cat_title', $term->name );
	} elseif ( is_tag() ) {
		/**
		 * Filters the tag archive page title.
		 *
		 * @since 2.3.0
		 *
		 * @param string $term_name Tag name for archive being displayed.
		 */
		$term_name = apply_filters( 'single_tag_title', $term->name );
	} elseif ( is_tax() ) {
		/**
		 * Filters the custom taxonomy archive page title.
		 *
		 * @since 3.1.0
		 *
		 * @param string $term_name Term name for archive being displayed.
		 */
		$term_name = apply_filters( 'single_term_title', $term->name );
	} else {
		return;
	}

	if ( empty( $term_name ) ) {
		return;
	}

	if ( $display ) {
		echo $prefix . $term_name;
	} else {
		return $prefix . $term_name;
	}
}

常見問題

FAQs
檢視更多 >