get_the_category_by_ID()
get_the_category_by_ID( int $cat_ID )
根据类别ID检索类别名称。
Retrieve category name based on category ID.
参数(Parameters)
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
$cat_ID | (int) | 必需 | 类别ID。 |
返回(Return)
(string|WP_Error)成功时类别名称,失败时WP_Error。
源码(Source)
/** * Retrieve category name based on category ID. * * @since 0.71 * * @param int $cat_ID Category ID. * @return string|WP_Error Category name on success, WP_Error on failure. */ function get_the_category_by_ID( $cat_ID ) { $cat_ID = (int) $cat_ID; $category = get_term( $cat_ID, 'category' ); if ( is_wp_error( $category ) ) return $category; return ( $category ) ? $category->name : ''; }
更新版本 | 源码位置 | 使用 | 被使用 |
---|---|---|---|
0.71 | wp-includes/category-template.php:108 | 1 function | 2 |
get_the_category_by_ID() 为WP2原创文章,链接:https://www.wp2.cn/functions/get_the_category_by_id/