WordPress中不同分类使用不同模板

2014-04-15阅读(4612)评论(0)牵着狗狗看MM

苏州实时公交查询

打开模板目录wp-content\themes\yourtheme文件夹
先复制一份category.php,命名为category-all.php
然后修改category.php如下

<?php 
$post = $wp_query->post; 
if ( in_category(array( 9,10,11,12,13,14 )) ) { 
include(TEMPLATEPATH . '/category-library.php'); 
} 
else if ( in_category('1') ) { 
include(TEMPLATEPATH . '/category-1.php'); 
} 
else if ( in_category('4') ) { 
include(TEMPLATEPATH . '/category-4.php'); 
} 
else if ( in_category('8') ) { 
include(TEMPLATEPATH . '/category-8.php'); 
} 
else { 
include(TEMPLATEPATH . '/category-simple.php'); 
} 
?> 

上面代码表示:
分类ID为“9,10,11,12,13,14”,使用category-library.php模板文件(即复制修改前的category.php,然后自己修改)
分类ID为“1”使用category-1.php模板文件
分类ID为“4”使用category-4.php模板文件
分类ID为“8”使用category-8.php模板文件
其他的则使用category-simple.php模板文件。

赞(0)
转载请注明来源:Web前端(W3Cways.com) - Web前端学习之路 » WordPress中不同分类使用不同模板
分享到: 更多 (0)