the_category_head

函数
the_category_head ( $before = '', $after = '' )
参数
  • (string) $before Optional. Text to display before the category. Default empty.
    Required:
    Default: (empty)
  • (string) $after Optional. Text to display after the category. Default empty.
    Required:
    Default: (empty)
相关
  • get_the_category_by_ID()
定义位置
相关方法
the_category_idthe_categorythe_category_rssupdate_category_cacheget_the_category
引入
0.71
弃用
0.71.0

the_category_head – 这个函数用来在一个页面的HTML头部输出类别信息。它可以用来提供关于一个文章所属类别的元数据。

打印一个类别,前后有可选的文本。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function the_category_head( $before = '', $after = '' ) {
global $currentcat, $previouscat;
_deprecated_function( __FUNCTION__, '0.71', 'get_the_category_by_ID()' );
// Grab the first cat in the list.
$categories = get_the_category();
$currentcat = $categories[0]->category_id;
if ( $currentcat != $previouscat ) {
echo $before;
echo get_the_category_by_ID($currentcat);
echo $after;
$previouscat = $currentcat;
}
}
function the_category_head( $before = '', $after = '' ) { global $currentcat, $previouscat; _deprecated_function( __FUNCTION__, '0.71', 'get_the_category_by_ID()' ); // Grab the first cat in the list. $categories = get_the_category(); $currentcat = $categories[0]->category_id; if ( $currentcat != $previouscat ) { echo $before; echo get_the_category_by_ID($currentcat); echo $after; $previouscat = $currentcat; } }
function the_category_head( $before = '', $after = '' ) {
	global $currentcat, $previouscat;

	_deprecated_function( __FUNCTION__, '0.71', 'get_the_category_by_ID()' );

	// Grab the first cat in the list.
	$categories = get_the_category();
	$currentcat = $categories[0]->category_id;
	if ( $currentcat != $previouscat ) {
		echo $before;
		echo get_the_category_by_ID($currentcat);
		echo $after;
		$previouscat = $currentcat;
	}
}

常见问题

FAQs
查看更多 >