Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!-- TEST -->
- start test
- <?php
- //get all child categories for category 6, then for each child category display the posts
- $parent = get_category($cat->category_parent);
- $parent_cat = $parent->cat_ID;
- $taxonomy = 'category';
- $cat_children = get_term_children($parent_cat, $taxonomy );
- // for each subcategory store in array
- foreach($cat_children as $subcategory)
- {
- $args=array(
- 'cat' => $subcategory,
- 'post_type' => 'post',
- );
- // print out category id to double check
- echo $subcategory;
- // the query
- $my_query = null;
- $my_query = new WP_Query($args);
- if( $my_query->have_posts() )
- {
- foreach( get_the_category() as $subcategory)
- {
- // post subcategory title
- echo $subcategory->name;
- // post items of each category
- while ($my_query->have_posts()) : $my_query->the_post(); ?>
- <p><?php the_title(); ?></p>
- <?php
- endwhile;
- }
- }
- }
- // Restore global post data stomped by the_post().
- wp_reset_query();
- ?>
- endtest
- <!-- END TEST -->
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement