List posts in sub-sub categories of a category.
-
I have a hierarchy of categories of A < Bs < Cs where A is the grandparent, B is the parent and C is the child. There are many Bs and many Cs.
There are no post in A. What I would like to do is to list B if the C under it has posts and list all the posts.
So the result I would like to see is B with postings listed in C(which is under B)
I found this code but somehow what it does is listing all the Bs including those with Cs that has no postings. I would like to only list those Bs that has postings under their Cs. Can anyone help me to troubleshoot the code? Thanks in advance.
<?php $categories = get_categories('hide_empty=0&parent=16'); foreach ($categories as $category) { //Display the sub category information using $category values like echo '<h2>'.$category->name.'</h2>'; echo '<ul>'; foreach (get_posts('cat='.$category->term_id) as $post) { setup_postdata( $post ); echo '<li><a href="'.get_permalink($post->ID).'">'.get_the_title().'</a></li>'; } echo '</ul>'; } ?>
Viewing 10 replies - 1 through 10 (of 10 total)
Viewing 10 replies - 1 through 10 (of 10 total)
- The topic ‘List posts in sub-sub categories of a category.’ is closed to new replies.