2014-10-31 89 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; 

      } 
     } 
     } 
    } 

回答

相關問題