Display posts exclusively in their category (not parent)
-
Hi all,
I am wanting to display posts in a child-category exclusively in the child category only. At the moment, by default, WordPress shows these posts in all parent categories as well…
Also, I am using the following snippet (below) to display child-categories on a parent page. Whilst it works, it displays the words “No categories” when there are no sub/child categories to display. So I was wondering if there was a better way to implement this, as I don’t want anything to appear if there are no child categories to show.
<?php $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); if ($term->parent == 0) { ?> <h2>Browse Sub-categories:</h2> <ul> <?php wp_list_categories('taxonomy=wpl_documents_category&depth=1&show_count=0 &hide_empty=0&title_li=&child_of=' . $term->term_id); ?> </ul> <?php } else { ?> <h2>Browse Sub-categories:</h2> <ul> <?php wp_list_categories('taxonomy=wpl_documents_category&show_count=0 &hide_empty=0&title_li=&child_of=' . $term->term_id); } ?> </ul>
Note: The above code shows multiple levels of child-category – so I need the updated code to do the same.
Any ideas/information on the above is greatly appreciated!
Thank you.
- The topic ‘Display posts exclusively in their category (not parent)’ is closed to new replies.