I have a custom taxonomy called product-categories. Currently all categories use the master template (taxonomy-product-categories.php).
The category tree is roughly as follows.
Products
- Cheese
-- Types of Cheese
--- Cheddar
--- Brie
--- Cheshire
-- Types of Milk
--- Cows Cheese
--- Goats Cheese
- Cakes
- Category
I want to set it so that all categories, including sub_categories in the cheese section of the tree use a cheese template (taxonomy-product-categories-cheese.php). With other templates for the other areas.
I've found a two year old post which appears to be the solution but does not appear to do anything.
Make Custom Taxonomy Category Use Parent Template
I've added the following to my functions.php
add_filter('template_include', 'cheese_term_template');
function cheese_term_template( $template ) {
if ( is_tax('classifications') ) {
// $parent = get_term_by('slug', 'cheese', 'classifications');
$parent = 13;
if ( term_is_ancestor_of( $parent, get_queried_object(), 'classifications' ) )
return get_template_directory() . '/taxonomy-product-categories-cheese.php';
}
return $template;
}
I though that it was looking at the top level category instead but when I did some tests it didn't work with that either. I wonder if it was because the taxonomy name has a hyphen in it.
I'd appreciate any help... Thanks
classifications
or is it calledproduct-categories
? The latter sounds like the rewrite slug.