WordPress函数get_category用于获取分类对象。
get_category( int|object $category, string $output=OBJECT, string $filter=\'raw\' )
函数参数
$category
整数或对象
分类的ID或分类对象
$output
字符串,默认值:OBJECT
返回的数据类型,默认返回对象,可选值:
- OBJECT:默认值,以对象的形式返回数据;
- ARRAY_A:以关联数组的形式返回数据;
- ARRAY_N:以数字数组的形式返回数据。
$filter
字符串,默认值:raw
对分类使用函数sanitize_term进行字段过滤
函数返回值
WP_Term Object( [term_id] => 1 [name] => 分类标题 [slug] => slug [term_group] => 0 [term_taxonomy_id] => 1 [taxonomy] => category [description] => 分类描述 [parent] => 0 [count] => 22 [filter] => raw [cat_ID] => 1 [category_count] => 22 [category_description] => 分类描述 [cat_name] => 分类标题 [category_nicename] => slug [category_parent] => 0)
函数使用示例
$category = get_category(2);echo \'<a href=\"\' . get_category_link($category->cat_ID) . \'\">\' . $category->name . \'</a>\';
扩展阅读
get_category()函数位于:wp-includes/category.php
相关函数:
- get_term()
- get_tag()
- get_category_children()
-=||=-收藏赞 (0)
不要再留垃圾评论了,主题君整理资源不容易,留几句鼓励的话吧。