Advertisement
alchymyth

cat and child cat posts

Apr 26th, 2011
1,744
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.61 KB | None | 0 0
  1. <?php
  2.     $parentCatName = single_cat_title('',false);
  3.     $parentCatID = get_cat_ID($parentCatName);
  4. $top_cat = get_category($parentCatID);
  5.     $childCats = get_categories( 'child_of='.$parentCatID );
  6. $childCats = array_merge(array($top_cat), $childCats);
  7.     if(is_array($childCats)):
  8.     foreach($childCats as $child){ ?>
  9.     <h2><?php echo $child->name; ?></h2>
  10.     <?php query_posts('cat='.$child->term_id);
  11.     while(have_posts()): the_post(); $do_not_duplicate = $post->ID; ?>
  12.     <!-- POST CODE -->
  13.  
  14.     <!-- END POST CODE -->
  15.     <?php
  16.     endwhile;
  17.     wp_reset_query();
  18.     }
  19.     endif;
  20.     ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement