自定义分类子类 - wordpress php

时间:2016-09-08 19:30:34

标签: php arrays wordpress taxonomy custom-taxonomy

我正在尝试按自定义分类法类别和子类别显示帖子列表。例如:

  • 摄影(类别)
    • 相机(子类别)
      • nikon 1(帖子标题)
      • nikon 2(帖子标题)
      • nikon 3(帖子标题)

现在我只看到最后一个填充了帖子的类别,需要查看列表中的所有类别帖子。

                <?php $custom_terms = get_terms('tool',
                    array('hide_empty' => false, 'hierarchical' => true));

                for( $i= 0 ; $i <count($custom_terms) ; $i++){
                    if( $custom_terms[$i]->parent == 0 ){

                echo $custom_terms[$i]->term_taxonomy_id .$custom_terms[$i]->name; 

                for( $j = 0 ; $j < count($custom_terms) ; $j++ ){
                    if( $custom_terms[$j]->parent == $custom_terms[$i]->term_id ){
                foreach($custom_terms as $custom_term) 
             {
            wp_reset_query();
                $args = array('post_type' => 'tools',
                    'tax_query' => array(
                        array('taxonomy' => 'tool','field' => 'term_id', 
                            'hierarchical' => true,'terms' => $custom_term->term_id,
                        ),
                    ),
                 );

                $loop = new WP_Query($args);
                    if($loop->have_posts()) {
        echo $custom_terms[$j]->term_taxonomy_id.$custom_terms[$j]->name; 

                                }
                            }
                        }
                    }
                }
            {
        {
    ?>

                <?php while($loop->have_posts()) : $loop->the_post(); ?>

                <?php
                    $args = array(
                        'post_type' => 'tools',
                        'tax_query' => array(
                            array(
                                'taxonomy' => 'tool', 
                                'field' => 'term_id',
                                'hierarchical' => true,
                                'terms' => $custom_term->term_id,
                                ),
                                            ),
                                );
                ?>

                <?php echo get_the_title(); ?>

<?php endif; ?> 
<?php  endwhile;  } } } ?>

0 个答案:

没有答案