主页 > 建站基础 > wordpress > wordpress
子分类的页面使用父级分类模板进行渲染
admin2022-04-06
简介/* * 使子分类的页面使用父级分类模板进行渲染 */ function category_template($template){ $category = get_queried_object(); if($category-parent !=0){ while($category-parent !=0){ $category = get_category($category-parent); }
/* * 使子分类的页面使用父级分类模板进行渲染 */ function 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 ); } add_filter('category_template', 'category_template');
很赞哦! (104)
上一篇:判断分类是否是顶级分类
下一篇:WP_query