WordPress函数get_category_by_slug根据分类的别名返回分类对象。
get_category_by_slug( string $slug )
函数参数
$slug
字符串
分类的别名,例如:develop
函数返回值
WP_Term Object( [term_id] => 1 [name] => 分类名称 [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] => 分类别名 [category_parent] => 0)
函数使用示例
$category = get_category_by_slug(\'develop\');echo \'<a href=\"\' . get_category_link($category->cat_ID) . \'\">\' . $category->name . \'</a>\';
扩展阅读
get_category_by_slug()函数位于:wp-includes/category.php
相关函数:
- get_term_by()
- get_term()
- get_category_children()
- get_category_by_path()
-=||=-收藏赞 (0)
不要再留垃圾评论了,主题君整理资源不容易,留几句鼓励的话吧。