wordpress不同分类设置不同模板

wordpress默认的通用模板是archive.php模板,那么如何根据不同分类设置不同模板呢?简单介绍一下实现代码!

具体实现代码如下:
把原来的archive.php通用模板复制到category-other.php,把下面内容添加到archive.php模板中,再根据需求新建其它模板。

具体代码

1
2
3
4
5
6
7
8
9
10
11
12
13
<?php
if (is_category(array(1,2,3))){
//分类id=1,2,3调用category-123模板
include(TEMPLATEPATH . '/category-123.php');
}elseif (is_category(array(4,5,6))){
//分类id=4,5,6调用category-456模板
include(TEMPLATEPATH . '/category-456.php');
}else{
//其它分类调用category-other
include(TEMPLATEPATH . '/category-other.php');
}
?>