网络营销电子商务研究中心

网络营销电子商务研究中心 (https://www.0058.net/index.php)
-   WordPress (https://www.0058.net/forumdisplay.php?f=68)
-   -   wordpress不同分类显示不同文章模板! (https://www.0058.net/showthread.php?t=4379)

topvip 2012-07-05 10:22 PM

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');//其他分类显示模板

下面有个 ?> 自己补上!


All times are GMT +8. The time now is 02:00 AM.

Powered by vBulletin Version 3.8.7
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.