我想在Wordpress中显示类别或分类下的所有子类别

时间:2016-09-05 11:10:22

标签: wordpress listview checkbox categories taxonomy

这是我的代码。它工作正常,但它只显示类别下最多5个子类别。每个类别都有10到20个子类别。现在我的代码出了什么问题?

我想在每个类别下打印所有子类别。怎么样?

<?php 
$args = array(
                'taxonomy' => 'custom_taxo',
                'parent'        => 0, 
                'orderby'       => 'name',
                'order'         => 'ASC',
                'hierarchical'  => 1,
                'hide_empty'    => 1,
                'pad_counts'    =>0
            );

            $categories = get_categories( $args );

            foreach ( $categories as $category ){

                echo "<li class='biz-cat'>";                

                echo '<label><input type="checkbox" id="type-'. $category->name . '" rel="'. $category->name . '">' . $category->name . '</label>';

                $sub_args = array(
                    'taxonomy' => 'custom_taxo',
                    'parent'        => $category->term_id, 
                    'orderby'       => 'name',
                    'order'         => 'ASC',
                    'hierarchical'  => 1,
                    'hide_empty'    => 1,
                    'pad_counts'    => 0
                );

                $sub_categories = get_categories( $sub_args );
                echo "<ul class='children'>";

                foreach ( $sub_categories as $sub_category ){
                    echo "<li>";

                    echo '<label><input type="checkbox" id="type-'. $sub_category->name . '" rel="'. $sub_category->name . '"> '. $sub_category->name . '</label>';
                    echo "</li>";    
                }
                echo "</ul>";
                echo "</li>";    
            }

1 个答案:

答案 0 :(得分:0)

当我改变&#39; hide_empty&#39; =&GT;真

然后它工作正常。

df