让你的博客每篇文章拥有不同的心情吧。wordpress不同分类、不同文章调用不同模板:
一、不同分类调用不同模板
<?php
$post = $wp_query->post;
if ( in_category('7') ) {
include(TEMPLATEPATH . '/archive-view.php');
}
else if ( in_category('12') ) {
include(TEMPLATEPATH . '/single12.php');
}
else if ( in_category('42') ) {
include(TEMPLATEPATH . '/single42.php');
}
else {
include(TEMPLATEPATH . '/archive-other.php');
}
?>
二、不同文章按照分类来调用不同模板
<?php
$post = $wp_query->post;
if ( in_category('7') ) {
include(TEMPLATEPATH . '/single-view.php');
}
else if ( in_category('3')) {
include(TEMPLATEPATH . '/single-case.php');
}
else if ( in_category('42') ) {
include(TEMPLATEPATH . '/single42.php');
}
else {
include(TEMPLATEPATH . '/archive-other.php');
}
?>
三、几点解释
1、这个应该同时可以扩展为按不同标签等来进行设置。
2、里面的数字为分类ID号,在后台编辑分类的地址上可以看到这个id号,对应写就行了。最后一个else是在之前没特别定义的分类样式。
3、以上代码分别修改的是archive.php和single.php,全部替换成如上代码。
网络推广经验,欢迎分享:广州SEO,网络推广 » WP不同分类文章调用不同模板