I think this should be a simple thing to do but I’m struggling to make it work.
What I have is the following:
Custom page type called ‘products’.
Products contain multiple categories and sub-categories.
The categories and sub-categories contain posts (products).
I want a custom template page to list the root categories which I’ve achieved by adding a template file called ‘archive-products.php’ – this now lists all root categories within the products post type.
Now, when I select a category I want to display a different template to list all sub-categories and products within that category but I can’t seem to get it to load the correct template file. I thought it should load the ‘archive-products.php’ file and I could detect the category and show a different template but I can’t seem to figure out how to do it.
I’m hoping this is something simple I’ve missed but I’ve been staring at the problem for so long I can’t seem to find a solution!
Thanks in advance.
If I understand correctly you have something like so:
You might need to add this to your
archive-products.php
as a conditional to test if a category has children, and if so show a different layout or design:Found this answer here: different-template-for-subcategory-any-conditions by triplebull
Hopefully it helps!