回首頁 wordpresswordpress – 顯示不同的文章內容頁面與sidebar
2009
05/17

wordpress – 顯示不同的文章內容頁面與sidebar

瀏覽:1,064人次
作者:英創達

上一篇 wordpress 自定客製化頁面模板
講到依據不同的類別,顯示不同的文章列表頁面

這次我們就來說依據不同類別,顯示不同的文章頁面

做法很簡單,將您的文章頁面single.php

另存新檔為single1.php 與single2.php 

再將原本single.php頁面的原始碼全部刪掉

放入下面語法

<?php
$post = $wp_query->post;
if ( in_category(’13′) ) {
include(TEMPLATEPATH . ‘/single2.php’);
} else {
include(TEMPLATEPATH . ‘/single1.php’);
}
?>

說明:

 in_category(’13′)就是您文章的分類

 補充:

這個用法也可以運用到sidebar

將sidebar另存新檔為sidebar_blog.php

再將原本<?php get_sidebar(); ?>刪掉改為

<?php
include(TEMPLATEPATH . ‘/sidebar_blog.php’);
?>

VN:F [1.9.6_1107]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.6_1107]
Rating: 0 (from 0 votes)

留下您的意見

(若看不到驗證碼,請重新整理網頁。)

    也許你也對以下文章有興趣: