WordPress子栏目模板继承

2016-05-06 18:20 阅读 8 次 评论关闭

WordPress子栏目模板继承的用法:原category.php改名为category-default.php,新建一个category.php文件用来做入口,代码片段如下

$catid = get_query_var('cat');
if ( file_exists(TEMPLATEPATH . '/category-' . $catid . '.php') )
die(include( TEMPLATEPATH . '/category-' . $catid . '.php'));
$cat = &get_category($catid);
if ( file_exists(TEMPLATEPATH . '/category-' . $cat->slug . '.php') )
die(include( TEMPLATEPATH . '/category-' . $cat->slug . '.php'));
$parent = $cat->category_parent;
while ($parent){
$cat = &get_category($parent);
if ( file_exists(TEMPLATEPATH . '/category-' . $cat->cat_ID . '.php') )
die(include (TEMPLATEPATH . '/category-' . $cat->cat_ID . '.php'));
if ( file_exists(TEMPLATEPATH . '/category-' . $cat->slug . '.php') )
die(include (TEMPLATEPATH . '/category-' . $cat->slug . '.php'));
}
include (TEMPLATEPATH . '/category-default.php');

版权声明:本文著作权归原作者所有,欢迎分享本文,谢谢支持!
转载请注明:WordPress子栏目模板继承 | 猎微网

评论已关闭!