您是否还要在子类别上加载父类别模板?将以下代码添加到当前激活的主题的functions.php文件中,或者您也可以在特定于站点的插件中添加以下代码。
function fwm_force_use_parent_category_template() {
$category = get_queried_object();
$templates = array();
// Add default category template files
$templates[] = "category-{$category->slug}.php";
$templates[] = "category-{$category->term_id}.php";
if ( $category->category_parent != 0 ) {
$parent = get_category( $category->category_parent );
if ( !empty($parent) ) {
$templates[] = "category-{$parent->slug}.php";
$templates[] = "category-{$parent->term_id}.php";
}
}
$templates[] = 'category.php';
return locate_template( $templates );
}
add_filter( 'category_template', 'fwm_force_use_parent_category_template' );