有些网友觉得就一个主题不好看,那么怎么办呢?用WordPress分类调用不同的主题,不同的分类,就会有不同的主题,拥有多元化的主题风格哦
一、分类:
分类页的话直接用category-ccyzk.php就可以了使不同的分类页使用不同的模版,ccyzk是分类的别名。
二、单页面:
1、在你的theme目录下找到日志主题(single-theme.php)和plugin目录下的日志主题(single-plugin.php);把默 认日志主题single.php复制一份,命名为single-all.php,之后把single.php的内容清空,加入以下代码:
这段代码的功能是自动判断如果分类的别名是theme,日志就自动调用single-theme.php;分类别名是plugin的话,就自动调用 single-plugin.php文件,没指定的话,就自动调用默认的日志主题文件single-all.php,这样就实现了不同分类的日志使用不同 主题的目的。
2、上面的代码也可以改成按分类目录ID来判断:
if ( in_category(’1′) ) {
include(TEMPLATEPATH . ‘/single-theme.php’);
}
elseif ( in_category(’2′) ) {
include(TEMPLATEPATH . ‘/single-plugin.php’);
}
else {
include(TEMPLATEPATH . ‘/single-all.php’);
}
?>
如果分类ID为1,就调用single-theme.php文件,分类ID为2,就调用single-plugin.php文件,效果和判断别名是一样的,根据自己爱好选择使用。
三、WordPress首页模板、page模版、single模版如何使用不同的header、footer、siderbar
通过命名才解决,比如说sidebar,你可以命名为sidebar-left.php、sidebar-right.php、sidebar-你想要的名字(可以随意没有规定).php,其他header、footer部分的改变和sidebar一样:
调用方式,用get_sidebar()函数,不过中间加(“名字”),就成了get_sidebar(“right”)之类的:
分类页的话直接用category-ccyzk.php就可以了使不同的分类页使用不同的模版。
2019年2月11日 17:54852015 368150Hello! Great stuff, please maintain us posted when you post again something like that! 436822
2018年8月18日 03:11830451 631503thank you dearly author , I identified oneself this web website extremely valuable and its full of excellent healthy selective data ! , I as properly thank you for the amazing food plan post. 849343
2018年8月15日 21:45879030 982991There is evidently a good deal to know about this. I consider you produced certain good points in capabilities also. 802075
2018年8月14日 18:45这个功能真的太好了。
2017年7月29日 10:40