View Single Post
  #1   IP: 218.2.67.86
Old 2012-07-05, 10:22 PM
topvip topvip is offline
超级版主
 
Join Date: 2006-01-04
Posts: 1206
topvip 正向着好的方向发展
Default wordpress不同分类显示不同文章模板!

1,在
function.php
最底部添加
Code:
function post_is_in_descendant_category( $cats, $_post = null )
 
{
 
foreach ( (array) $cats as $cat ) {
 
// get_term_children() accepts integer ID only
 
$descendants = get_term_children( (int) $cat, ‘category’);
 
if ( $descendants && in_category( $descendants, $_post ) )
 
return true;
 
}
 
return false;
 
}
2,新建
single-news.php
single-pro.php
single-other.php


single.php
内 只有这些,别的内容都删掉
Code:
<?php if ( in_category( '3' ) || post_is_in_descendant_category( 3 ) ) {
 
include(TEMPLATEPATH . '/single-pro.php');//id为3的分类显示模板
 
} elseif( in_category( '5' ) || post_is_in_descendant_category( 5 ) ) {
 
include(TEMPLATEPATH . '/single-news.php');}//id为5的分类显示模板
 
else{include(TEMPLATEPATH . '/single-other.php');//其他分类显示模板
下面有个 ?> 自己补上!
Reply With Quote