2011-01-14 9 views
0

Hey!私はカテゴリのサブカテゴリだけを抽出する関数が必要です。サブカテゴリのサブカテゴリではなく、ワードプレスで。ありがとう!ワードプレスカテゴリ/サブカテゴリ

 <?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

+0

if文(==と!==)に二重等号があることを覚えておいてください。 – Calum

答えて

0

何か?

foreach($subcategorii as $subcategorie) { 

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

    // do stuff 

    } 

}