the_category_id

函数
the_category_id ( $display = true )
参数
  • (bool) $display Optional. Whether to display the output. Default true.
    Required:
    Default: true
返回值
  • (int) Category ID.
相关
  • get_the_category()
定义位置
相关方法
the_categorythe_category_headthe_category_rssget_the_category_by_idthe_author_id
引入
0.71
弃用
0.71.0

the_category_id – 这个函数用来显示分配给一个文章的第一个类别的ID。它对需要知道某个特定文章的类别ID的开发者很有用。

返回或打印一个类别ID。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function the_category_ID($display = true) {
_deprecated_function( __FUNCTION__, '0.71', 'get_the_category()' );
// Grab the first cat in the list.
$categories = get_the_category();
$cat = $categories[0]->term_id;
if ( $display )
echo $cat;
return $cat;
}
function the_category_ID($display = true) { _deprecated_function( __FUNCTION__, '0.71', 'get_the_category()' ); // Grab the first cat in the list. $categories = get_the_category(); $cat = $categories[0]->term_id; if ( $display ) echo $cat; return $cat; }
function the_category_ID($display = true) {
	_deprecated_function( __FUNCTION__, '0.71', 'get_the_category()' );

	// Grab the first cat in the list.
	$categories = get_the_category();
	$cat = $categories[0]->term_id;

	if ( $display )
		echo $cat;

	return $cat;
}

常见问题

FAQs
查看更多 >