WordPress函数:category_exists 判断分类是否存在
在WordPress中 判断一个分类是否存在,只需要使用 category_exists 函数。
函数源码:
function category_exists( $cat_name, $category_parent = null ) {
$id = term_exists( $cat_name, 'category', $category_parent );
if ( is_array( $id ) ) {
$id = $id['term_id'];
}
return $id;
}
从源码中可以看出,使用了函数 term_exists。
term_exists 更加通用,可是检查任意文章类型的分类是否存在。
-
WordPress函数:get_posts 查询一组文章的好方法get_posts 和 WP_Query 支持的参数一模一样
-
WordPress函数:has_post_thumbnail判断文章是否设置了特色图像函数has_post_thumbnail是一个用于判断文章是否设置了特色图像WordPress函数,也就是我们常说的微缩图。
-
WordPress函数:add_theme_support 为主题添加功能特性让自己的主题支持更多的特性
-
WordPress 函数:get_comments 评论查询 参数大全get_comments 参数太多了……
-
WordPress do_action() 和 do_action_ref_array() 区别WordPress do_action() 和 do_action_ref_array() 区别
-
WordPress函数:wp_doing_ajax 判断是否是 AJAX 请求WordPress函数:wp_doing_ajax 判断是否是 AJAX 请求
暂无评论,抢个沙发...