2010-11-18 23 views
1

类别和子类别如何WordPress的如果为0的职位也是一个类别显示所有类别子类。我尝试过,但它显示的类别至少有一个职位在一个类别。我想显示的类别也有0帖子也。如何列出在WordPress

谢谢

回答

1

get_categories功能,有一个名为 “hide_empty” 参数。例如:

<?php $cats = get_categories('hide_empty=0'); ?> 
1

使用get_categories()函数获取所有类别。

$args = array(
    'type'      => 'post', 
    'child_of'     => 0, 
    'parent'     => '', 
    'orderby'     => 'name', 
    'order'     => 'ASC', 
    'hide_empty'    => 1,  // hide empty categories [0] false 
    'hierarchical'    => 1, 
    'exclude'     => '', 
    'include'     => '', 
    'number'     => '', 
    'taxonomy'     => 'category', 
    'pad_counts'    => false 
); 
$categories = get_categories($args); 

将所有类别存储在变量中后,请使用print_r查看可以使用的数组的所有值。

echo "<pre>"; 
     print_r($slider_category); 
    echo "</pre>"; 

当您使用的print_r你会看到这样

Array (
[0] => stdClass Object 
    (
     [term_id] => 11 
     [name] => Architecture 
     [slug] => architecture 
     [term_group] => 0 
     [term_taxonomy_id] => 11 
     [taxonomy] => category 
     [description] => 
     [parent] => 0 
     [count] => 3 
     [cat_ID] => 11 
     [category_count] => 3 
     [category_description] => 
     [cat_name] => Architecture 
     [category_nicename] => architecture 
     [category_parent] => 0 
    )) 

更改代码,你会得到你想要的。