类别/子类别显示问题

时间:2015-12-18 16:20:07

标签: php wordpress categories

在此页面上:http://realtor.kirkdahle.com/resources-test/我有自定义帖子类型“资源”的众多类别和子类别。我目前正在努力让侧边栏显示类别和子类别以及显示所有帖子的主体。

所有帖子都在子类别中,由主要类别组织。如果没有至少一个帖子也检查主类别以及子类别,那么NOTHING将显示在主类别OR子类别的列表中。这是我的代码:

 <?php 
    // gets all categories 
    $taxonomies = array( 
        'resource-cat'
    );

    $taxonomy_name = 'resource-cat';

    $args = array(
        'orderby'           => 'name', 
        'order'             => 'ASC',
        'hide_empty'        => true, 
        'exclude'           => array(), 
        'exclude_tree'      => array(), 
        'include'           => array(),
        'number'            => '', 
        'fields'            => 'all', 
        'slug'              => '',
        'parent'            => '',
        'hierarchical'      => false, 
        'child_of'          => 0,
        'childless'         => false,
        'get'               => '', 
        'name__like'        => '',
        'description__like' => '',
        'pad_counts'        => false, 
        'offset'            => '', 
        'search'            => '', 
        'cache_domain'      => 'core'
    ); 

    $terms = get_terms($taxonomies, $args);

    echo '<ul id="top-cats">';
    foreach ($terms as $term) { 
        if(!$term->parent)
             echo '<li class="filter_bold"><a href="'.get_term_link( $term ).'">'.$term->name.'</a></li>';

        $termchildren = get_term_children( $term->term_id, $taxonomy_name );
        echo '<ul>';
        foreach ( $termchildren as $child ) {
            $subterm = get_term_by( 'id', $child, $taxonomy_name );
            if($subterm->count != 0)
                echo '<li><a href="' . get_term_link( $child, $taxonomy_name ) . '">' . $subterm->name . '</a></li>';
        }
        echo '</ul>';
    }
    echo '</ul>';
  ?>

任何有关如何调整此项的建议都将非常受欢迎。

1 个答案:

答案 0 :(得分:0)

我通过改变

解决了这个问题
'hierarchical'      => 1,
相关问题