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
檢視更多 >