WordPress企业主题定制/开发/优化

WP根据分类名称获取分类ID

首页 » WORDPRESS主题技术 » WP根据分类名称获取分类ID

说明
根据分类名称取得分类的ID

用法

参数
$cat_name
(字符) (可选) 默认值: 'General' 并且可以是任意分类名称.

默认值: 'General'
返回值:(integer if 0, string if ID) 0, if failure and ID of category on success.

示例

基本示例
这是一个在LOOP中使用的一个简单的例子。

<?php
$category_id = get_cat_ID('Category Name');
$q = 'cat=' . $category_id;
query_posts($q);
if (have_posts()) : while (have_posts()) : the_post();

the_content();

endwhile; endif;
?>

注:
get_cat_ID() 存在于 wp-includes/category.php.

相关项目

  • WordPress外贸企业主题

  • 最近更新

  • 热门标签