首页 文章

类别/子类别显示问题

提问于
浏览
0

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

所有帖子都在子类别内,由主要类别组织 . 如果没有至少一个帖子也检查主类别以及子类别,那么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

    我通过改变解决了它

    'hierarchical'      => 1,
    

相关问题