the_category_ID()
云策文档标注
概述
the_category_ID() 是一个已弃用的 WordPress 函数,用于获取或输出当前文章的第一个分类的 ID。它已被 get_the_category() 替代。
关键要点
- 函数已弃用:自 WordPress 0.71 版本起,建议使用 get_the_category() 替代。
- 功能:返回或输出当前文章的第一个分类的 ID。
- 参数:$display(布尔值,可选),控制是否直接输出 ID,默认为 true(输出)。
- 返回值:返回分类 ID(整数)。
代码示例
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;
}注意事项
- 使用此函数会触发弃用警告,建议更新代码以避免兼容性问题。
- 相关函数:get_the_category() 用于检索文章分类,_deprecated_function() 用于标记弃用函数。
原文内容
Returns or prints a category ID.
Description
See also
Parameters
$displaybooloptional-
Whether to display the output.
Default:
true
Source
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;
}
Changelog
| Version | Description |
|---|---|
| 0.71 | Introduced. |