get_cat_name()
get_cat_name( int $cat_id )
从类别的ID中检索类别的名称。
Retrieve the name of a category from its ID.
参数(Parameters)
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
$cat_id | (int) | 必需 | 类别ID |
返回(Return)
(string)类别名称,如果类别不存在,则为空string。
源码(Source)
/** * Retrieve the name of a category from its ID. * * @since 1.0.0 * * @param int $cat_id Category ID * @return string Category name, or an empty string if category doesn't exist. */ function get_cat_name( $cat_id ) { $cat_id = (int) $cat_id; $category = get_term( $cat_id, 'category' ); if ( ! $category || is_wp_error( $category ) ) return ''; return $category->name; }
更新版本 | 源码位置 | 使用 | 被使用 |
---|---|---|---|
1.0.0 | wp-includes/category.php:211 | 5 | 2 |
笔记(Notes)
基本示例
get_cat_name() 为WP2原创文章,链接:https://www.wp2.cn/functions/get_cat_name/