Advertisement
alchymyth

third level cat posts

Jul 8th, 2012
439
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.07 KB | None | 0 0
  1. <?php
  2. $top_cat = 'products';
  3. echo '<h3>' . $top_cat . '</h3>';
  4. $cat = get_term_by('name',$top_cat,'category');
  5. if( $cat ) :
  6.     $sub_cats = get_categories('parent='.$cat->term_id);
  7.     if( $sub_cats ) :
  8.     foreach( $sub_cats as $sub_cat ) {
  9.  
  10.     echo '<h4>' . $sub_cat->name . '</h4>'; //OUTPUT SUB CATEGORY TITLE
  11.         $sub_sub_cats = get_categories('parent='.$sub_cat->term_id);
  12.        
  13.         if( $sub_sub_cats ) :
  14.         foreach( $sub_sub_cats as $sub_sub_cat ) {
  15.         echo '<h5>' . $sub_sub_cat->name . '</h4>'; //OUTPUT SUB SUB CATEGORY TITLE
  16.  
  17.         $args = array(
  18.             'category__in' => array($sub_sub_cat->term_id),
  19.             'posts_per_page' => -1
  20.             );
  21.            
  22.         $sub = new WP_Query( $args );
  23.         if( $sub->have_posts() ) : while( $sub->have_posts() ) : $sub->the_post();
  24.             echo '<p>'; the_title(); echo '</p>'; //YOUR POST OUTPUT CODE//
  25.         endwhile;
  26.         endif;
  27.         wp_reset_postdata();
  28.        
  29.         } //ends foreach( $sub_sub_cats as $sub_sub_cat) //
  30.         endif; //ends if( $sub_sub_cats ) //
  31.        
  32.     } //ends foreach( $sub_cats as $sub_cat) //
  33.     endif; //ends if( $sub_cats ) //
  34.    
  35. endif; //ends if( $cat ) //
  36. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement