
third level cat posts
By:
alchymyth on
Jul 8th, 2012 | syntax:
PHP | size: 1.07 KB | hits: 78 | expires: Never
<?php
$top_cat = 'products';
echo '<h3>' . $top_cat . '</h3>';
$cat = get_term_by('name',$top_cat,'category');
if( $cat ) :
$sub_cats = get_categories('parent='.$cat->term_id);
if( $sub_cats ) :
foreach( $sub_cats as $sub_cat ) {
echo '<h4>' . $sub_cat->name . '</h4>'; //OUTPUT SUB CATEGORY TITLE
$sub_sub_cats = get_categories('parent='.$sub_cat->term_id);
if( $sub_sub_cats ) :
foreach( $sub_sub_cats as $sub_sub_cat ) {
echo '<h5>' . $sub_sub_cat->name . '</h4>'; //OUTPUT SUB SUB CATEGORY TITLE
$args = array(
'category__in' => array($sub_sub_cat->term_id),
'posts_per_page' => -1
);
$sub = new WP_Query( $args );
if( $sub->have_posts() ) : while( $sub->have_posts() ) : $sub->the_post();
echo '<p>'; the_title(); echo '</p>'; //YOUR POST OUTPUT CODE//
endwhile;
endif;
wp_reset_postdata();
} //ends foreach( $sub_sub_cats as $sub_sub_cat) //
endif; //ends if( $sub_sub_cats ) //
} //ends foreach( $sub_cats as $sub_cat) //
endif; //ends if( $sub_cats ) //
endif; //ends if( $cat ) //
?>