我注意到你正在使用is_category() 在你的函数中,这意味着你的目标是默认/核心category 分类法,而不是自定义分类法,因此您应该使用category_template 钩例如。
add_filter( \'category_template\', \'load_new_custom_tax_template\');
function load_new_custom_tax_template ($tax_template) {
// I don\'t check for is_category() because we\'re using the category_template filter.
return dirname( __FILE__ ) . \'/templates/category.php\';
}
或者,您可以使用
template_include hook 运行
afterthe
<type>_template hook 例如
category_template 和
taxonomy_template:
add_filter( \'template_include\', \'load_new_custom_tax_template\');
function load_new_custom_tax_template ($tax_template) {
if (is_category()) {
$tax_template = dirname( __FILE__ ) . \'/templates/category.php\';
}
return $tax_template;
}
请注意,其他插件也可以覆盖模板,因此您可能希望使用较低的优先级,即较大的数字作为
add_filter(). E、 g.20如所示
add_filter( \'category_template\', \'load_new_custom_tax_template\', 20)