Wordpress类别/子类别

时间:2011-01-14 18:14:27

标签: php 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;    
   } 
}

?>

1 个答案:

答案 0 :(得分:0)

这样的事,也许?

foreach($subcategorii as $subcategorie) {

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

   // do stuff

   }  

 }