只做利于SEO的网站,提供网站建设、SEO、网站代运营等服务。服务中心 | 建站流程 | 网站地图

Wordpress多个分类采用同一个模板

2021-10-15小猴建站 阅读()相关主题:wordpress

网站有多个分类采用不同模板的情况比较多,Wordpress主题模板文件夹可以写多个模板,比如

catagory-5.php
catagory-6.php
catagory-7.php
……

对应的页面分类分别是5、6、7,系统能够自动识别对应的模板,如下图:

多个页面有使用同一个模板

比如分类5、6、7都采用 category-5.php 模板,主题模板下一般有category.php文件,如果没有自己建一个,内容如下:

<?php
if (if(is_category(array(5,6,7))){
    include(TEMPLATEPATH . '/category-5.php'); //分类5,6,7采用category-5.php模板
}elseif(is_category(1)){
    include(TEMPLATEPATH . '/category-1.php'); //分类1采用category-1.php模板,也可以不写
}elseif(is_category(2)){
    include(TEMPLATEPATH . '/category-2.php'); //分类2采用category-2.php模板,也可以不写
}else{
    include(TEMPLATEPATH . '/category-other.php'); //其余分类默认采用category-other.php模板
}
?>