2011-01-14 128 views
0

嘿!我需要一個函數,在wordpress中只提取子類別的子類別,而不是子類別的子類別。謝謝!WordPress的類別/子類

 <?php if (is_category()) { 

    $this_category = get_category($cat); 
    if (get_category_children($this_category->cat_ID) != "") { 


    $args = array('child_of' => $this_category->cat_ID); 
    $subcategorii = get_categories($args); 
    foreach($subcategorii as $subcategorie) { 
      echo ' <li class="postWrapper" id="categorie"><a href="'.$subcategorie->link.'"><h5>'.$subcategorie->name.'</h5></a>'; 
      query_posts('cat='.$subcategorie->term_id.'&posts_per_page=3'); 
      if (has_post_thumbnail()) the_post_thumbnail('mic'); 
     echo '<ul>';  
     if (have_posts()) : while (have_posts()) : the_post(); 

      echo '<li><a href="'.get_permalink().'">'.get_the_title().'</a></li>'; 

     endwhile; 
     echo '</ul>'; 
     echo '</li>'; 
     else: 
     echo 'niciun articol!'; 
     endif; 

    //Reset Query 
    wp_reset_query(); 
    } 
    } else { 
     query_posts('cat='.$this_category->cat_ID.'&posts_per_page=3'); 
     echo ''; 
     if (have_posts()) : while (have_posts()) : the_post(); 

     echo '<li class="postWrapper" id="post">'; 

     echo '<a href="'.get_permalink().'">'; if (has_post_thumbnail()) the_post_thumbnail('mic');  

      echo '<h3 class="postTitle">'.get_the_title().'</h3></a>'; 




      echo '</li>'; 

     endwhile; 
     echo ''; 
     else: 
     echo 'niciun articol!'; 
     endif;  
    } 
} 

?> 
+0

到目前爲止你做了什麼? – Shoban 2011-01-14 18:15:40

回答

0

這樣的事情,也許呢?

foreach($subcategorii as $subcategorie) { 

    if ($subcategorie->post_parent == $this_category->cat_ID) { 

    // do stuff 

    } 

}