首页 > WordPress学习 > WordPress子主题下不同分类使用不同模板使用TEMPLATEPATH报错 应使用get_stylesheet_directory()函数

WordPress子主题下不同分类使用不同模板使用TEMPLATEPATH报错 应使用get_stylesheet_directory()函数

时间:2023年4月10日 分类:WordPress学习 浏览量:217

今天遇到个尴尬的事情,使用子主题来测试模板,需要对分类做不同分类的模板区分,结果一直报错,使用的是父主题的调用代码:

<?php 
if (is_category(array(1))){ 
include(TEMPLATEPATH . '/template/zhuce.php'); 
}elseif (is_category(array(2))){ 
include(TEMPLATEPATH . '/template/jizhang.php'); 
}elseif (is_category(array(3))){ 
include(TEMPLATEPATH . '/template/zizhi.php'); 
}elseif (is_category(array(4))){ 
include(TEMPLATEPATH . '/template/chanquan.php'); 
}else{ 
include(TEMPLATEPATH . '/template/newslist.php'); 
} 
?>

在子主题下,一直无法生效,一直报错。

一开始以为哪里标点符号没复制,一个字一个字检查,没问题啊!

然后再寻找,才想起来,子主题include文件,得用另外一个函数实现:get_stylesheet_directory(),新代码:

<?php 
if (is_category(array(1))){ 
include(get_stylesheet_directory() . '/template/zhuce.php'); 
}elseif (is_category(array(2))){ 
include(get_stylesheet_directory() . '/template/jizhang.php'); 
}elseif (is_category(array(3))){ 
include(get_stylesheet_directory() . '/template/zizhi.php'); 
}elseif (is_category(array(4))){ 
include(get_stylesheet_directory() . '/template/chanquan.php'); 
}else{ 
include(get_stylesheet_directory() . '/template/newslist.php'); 
} 
?>

这下子,终于能测试模板页面了,get_stylesheet_directory()函数用于获取当前启用的主题目录的服务器绝对路径,子主题使用刚刚好。

版权声明:本文采用知识共享 署名4.0国际许可协议 [BY-NC-SA] 进行授权

文章名称:WordPress子主题下不同分类使用不同模板使用TEMPLATEPATH报错 应使用get_stylesheet_directory()函数

文章链接:https://news.yynnw.com/169.html

该作品系作者结合个人学习经验及互联网相关知识整合。如若侵权请通过投诉通道提交信息,我们将按照规定及时处理。

觉得文章有用就打赏一下文章作者

微信扫一扫打赏

标签:

最新文章