wordpress获取当前不同分类的别名、ID号、文章数
在自己建网站时,往往在不同分类调用出不同的属性,需要结合调用各类分类的别名或者分类的ID号,如何让WORDPRESS程序自动调用出不同分类的别名和ID号呢?
调用分类的别名:
<?
global $wp_query;
$cat_ID = get_query_var('cat');
$category = get_category($cat_ID);
echo $category->slug;
?>
global $wp_query;
$cat_ID = get_query_var('cat');
$category = get_category($cat_ID);
echo $category->slug;
?>
调用分类的ID号:
<?
global $wp_query;
$cat_ID = get_query_var('cat');
$category = get_category($cat_ID);
echo $category->cat_ID;
?>
global $wp_query;
$cat_ID = get_query_var('cat');
$category = get_category($cat_ID);
echo $category->cat_ID;
?>
调用分类的文章数:
<?
global $wp_query;
$cat_ID = get_query_var('cat');
$category = get_category($cat_ID);
echo $category->count;
?>
global $wp_query;
$cat_ID = get_query_var('cat');
$category = get_category($cat_ID);
echo $category->count;
?>
调用更多的分类的属性:
get_category() 根据分类ID获得指定分类全部信息,以数组或是对象的形式返回,以下是该函数的返回值示例:
//ID 分类和标签混编
[term_id] => 5
//分类名
[name] => Cat Name
//分类别名
[slug] => cat
//N/A
[term_group] => 0
//同 term_id
[term_taxonomy_id] => 5
//分类法,也就是分类还是标签
[taxonomy] => category
//分类描述
[description] =>
//父级ID
[parent] => 70
//N/A
[count] => 0
//分类ID
[cat_ID] => 5
//N/A
[category_count] => 0
//同 description
[category_description] =>
//同 name
[cat_name] => Category Name
//同 slug
[category_nicename] => category-name
//同 parent
[category_parent] => 70