子分类使用父分类模板
function f_category_template($template){
$category = get_queried_object();
if($category->parent !='0'){
while($category->parent !='0'){
$category = get_category($category->parent);
}
}
$templates = array();
if ( $category ) {
$templates[] = "category-{$category->slug}.php";
$templates[] = "category-{$category->term_id}.php";
}
$templates[] = 'category.php';
return locate_template( $templates );
}
原文
文章介绍了WordPress中的functionf_category_template函数,它根据父分类关系动态加载模板。当查询的类别有父类别时,函数会递归获取并包含相应的category.php或自定义slug或term_id的模板文件。
2408

被折叠的 条评论
为什么被折叠?



