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
查看更多 >