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');//其他分类显示模板
下面有个 ?> 自己补上!