wordpress不同分类(栏目)设置不同模板

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

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

<?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’);
}
?>

为您推荐

发表回复