时间:2024-03-13
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()
Copyright © 2019-2024 2543.cn