如何显示所有的分类和<强>子类在<强> 的wordpress 如果具有0发表的类别也。我尝试,但它显示的是,它们是在一个类别的至少1交类别。我想其具有显示类别的 0帖同时

感谢您

有帮助吗?

解决方案

请参阅 get_categories 功能,有一种所谓的 “hide_empty” 参数。例如:

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

其他提示

使用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
    ))

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top