• 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.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Samnabz

    (@samnabz)

    Sorry, I know I only posted this yesterday, but I really need this sorted as soon as possible.

    I’ve tried many different methods that I’ve found, but none that have worked so far.

    Any info is greatly appreciated!

    Thread Starter Samnabz

    (@samnabz)

    Still need help with this please..

    Also, I should mention that this is for a custom post type – taxonomy = wpl_documents_category

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Display posts exclusively in their category (not parent)’ is closed to new replies.