我有一个称为产品类别的自定义分类法。目前,所有类别都使用主模板(taxonomy product categories.php)。
类别树大致如下所示。
Products
- Cheese
-- Types of Cheese
--- Cheddar
--- Brie
--- Cheshire
-- Types of Milk
--- Cows Cheese
--- Goats Cheese
- Cakes
- Category
我想将其设置为所有类别,包括树的cheese部分中的sub\\u类别,都使用cheese模板(taxonomy product categories cheese.php)。使用其他区域的其他模板。我发现了一个两年前发布的帖子,它似乎是解决方案,但似乎什么都没做。
Make Custom Taxonomy Category Use Parent Template
我在函数中添加了以下内容。phpadd_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;
}
我认为它是在寻找顶级类别,但当我做了一些测试,它也没有工作。我想知道这是否是因为分类名称中有一个连字符。我很感激任何帮助。。。谢谢