0

I have created custom post types called Internal products

I Have a page page-internal-products.php which list all the custom taxonomy for the Custom post type Internal product

On clicking on the taxonomies takes me to a page which lists the sub taxonomies for the particular parent taxonomy for which i have created the page called taxonomy-internalproducts_categories.php

On clicking on the sub taxonomy. I need to go to a page which lists all the products for this sub taxonomy. How can I achieve this?

rahul251
  • 68
  • 1
  • 2
  • 13

1 Answers1

0

You can access the currently queried object with the get_queried_object() function and then check to see if the category has a parent or not. If it has - display posts in it, if it doesn't display all categories belonging to this category.

Here is an example code to do that:

$category = get_queried_object();
if ( $category->parent ) {
    // This is a sub-category
    get_template_part( 'internal-products', 'list' );
} else {
    // This is a main category
    get_template_part( 'internal-products', 'categories-list' );
}

What this code will do is that it will include a theme file called internal-products-list.php or internal-products.php if the current category is a sub-category. Otherwise it will include either internal-products-categories-list.php or internal-products.php.

You can of course just write all of your code within the if/else blocks - that's up to you.

Nikola Ivanov Nikolov
  • 5,022
  • 1
  • 26
  • 27
  • I seem to be doing something wrong. My taxonomy-internalproducts_categories.php page now just has the piece of code that you gave. I created a page internal-products-list.php which lists all the products and internal-products-categories-list.php which lists all the sub taxonomies – rahul251 Nov 15 '12 at 11:30
  • What does it display? Do you always see the list of posts, or what? Can you give me an example URL or a screenshot of what you see, because I couldn't quite understand what's not working :) – Nikola Ivanov Nikolov Nov 15 '12 at 11:35
  • Awesome! Its working now. Thanks a lot Bro :) Was searching for a solution for a long time . – rahul251 Nov 15 '12 at 11:39
  • Please feel free to accept my answer - this way your question won't remain in the "Unanswered" section :) – Nikola Ivanov Nikolov Nov 15 '12 at 12:29