I have a WordPress website that has a category with two subcategories.
Now, how is it possible to show the content (the subcategories items/content) on the parent category?
2 Answers
One possibility:
<?php
$sub_cats = get_categories('parent=" . get_query_var("cat'));
if( $sub_cats ) :
foreach( $sub_cats as $sub_cat ) :
$sub_query = new WP_Query( array(
'category__in' => array( $sub_cat->term_id ),
'posts_per_page' => -1)
);
if ( $sub_query->have_posts() ) :
while( $sub_query->have_posts() ) : $sub_query->the_post();
//your output//
endwhile;
endif;
endforeach;
endif;
?>
http://codex.wordpress.org/Function_Reference/get_categories
http://codex.wordpress.org/Class_Reference/WP_Query