2014-10-31 192 views
0

我需要按此顺序显示列表。parent-sub-category-title => sub-category-title =>子类别的帖子。下面的代码让我成为父级标题,但不给我帖子。谁能告诉我为什么?如何显示父类别及其子类别帖子的列表

父类标题

子类别标题

子类,后

//get all categories then display all posts in each term 
    $taxonomy = 'commongood-categories'; //change this name if you have taxonomy 
    $param_type = 'category__in'; 
    $term_args=array(
    'orderby' => 'name', 
    'order' => 'ASC' 
    ); 
    $terms = get_terms($taxonomy,$term_args); 
    if ($terms) { 

     foreach($terms as $term){ //this foreach is for top level 
     if($term->parent == 0){ 
     echo '<h2>'.$term->name.' </h2>'; //get top level category name 
     $term_args=array(
     'orderby' => 'name', 
     'order' => 'ASC', 
     'child_of' => $term->term_id 

     ); 

     $termss = get_terms($taxonomy,$term_args); 
     foreach($termss as $terms) { 
     $args=array(
      "$param_type" => array($terms->term_id), 
      'post_type' => 'commongood', 
      'post_status' => 'publish', 
      'posts_per_page' => -1, 
      'caller_get_posts'=> 1 

      ); 


      $my_query = new WP_Query($args); 

      <?php while ($my_query->have_posts()) : $my_query->the_post(); ?> 
       <li class="series-bubble"> 
       <div class="stext"> 
        <span class="stitle"><a href="<?php echo get_permalink(); ?>"><?php if(get_field('optional_title')) { echo get_field('optional_title'); } else echo get_the_title(); ?></a></span> 
        <span class="scontent"><a href="<?php echo get_permalink(); ?>"><?php echo get_the_excerpt(); ?></a></span> 
       </div> 
       </li> 
      <?php endwhile; 

      } 
     } 
     } 
    } 

回答