2011-10-22 105 views
1

我正在使用Wordpress。我有一個電影評論網站叫做http://filmblurb.org。對於我的博客帖子,我試圖創建不同類別的帖子。在「評論」類別下,我有一個「詳細信息」框,作爲我所有評論的元信息。問題是,當我嘗試創建一個具有「功能」或其他類別的帖子時,「詳細信息」框仍然存在。基本上,我想嘗試創建一個PHP if語句,當我只寫一個「評論」帖子時,它只會返回下面的代碼序列。我在Wordpress中使用「get_post_meta」標籤來填寫這個「詳細信息」框,用於填寫每篇「評論」文章。示例文章可以在這裏找到:http://www.filmblurb.org/reviews/97。有人可以幫助我嗎?我會很感激。如果我需要更多地解釋,請告訴我。Wordpress上的PHP條件語句幫助

<div class="box"> 
    <div class="boxheader">Details</div> 
    <div class="text"> 
    <h1>Genre</h1> 
    <p><?php echo get_post_meta($post->ID, 'genre', true); ?></p> 
    <h1>Rated</h1> 
    <p><?php echo get_post_meta($post->ID, 'rated', true); ?></p> 
    <h1>Release Date</h1> 
    <p><?php echo get_post_meta($post->ID, 'releasedate', true); ?></p> 
    <h1>Runtime</h1> 
    <p><?php echo get_post_meta($post->ID, 'runtime', true); ?></p> 
    <h1>Director</h1> 
    <p><?php echo get_post_meta($post->ID, 'director', true); ?></p> 
    <h1>Cast</h1> 
    <p><?php echo get_post_meta($post->ID, 'cast', true); ?></p> 
    <h1>Grade</h1> 
    <p><?php echo get_post_meta($post->ID, 'grade', true); ?></p> 
    </div> 
</div> 

回答

3
<?php if(is_category('reviews')) : ?> 
    <div class="box"> 
     <div class="boxheader">Details</div> 
     <div class="text"> 
      <h1>Genre</h1> 
      <p><?php echo get_post_meta($post->ID, 'genre', true); ?></p> 
      <h1>Rated</h1> 
      <p><?php echo get_post_meta($post->ID, 'rated', true); ?></p> 
      <h1>Release Date</h1> 
      <p><?php echo get_post_meta($post->ID, 'releasedate', true); ?></p> 
      <h1>Runtime</h1> 
      <p><?php echo get_post_meta($post->ID, 'runtime', true); ?></p> 
      <h1>Director</h1> 
      <p><?php echo get_post_meta($post->ID, 'director', true); ?></p> 
      <h1>Cast</h1> 
      <p><?php echo get_post_meta($post->ID, 'cast', true); ?></p> 
      <h1>Grade</h1> 
      <p><?php echo get_post_meta($post->ID, 'grade', true); ?></p> 
     </div> 
    </div> 
<?php endif; ?> 

該參數可以是類別名稱,slug或ID。 進一步參考檢查the wordpress codex on the conditional tag "is_category()"

0

您有幾個選擇。

最好的一個可能是爲每個後期類別創建一個特殊的模板。 如果你不知道什麼樣的模板,請在這裏瞭解一切: http://codex.wordpress.org/Pages#Page_Templates

其他的方法是在CSS中。

在body標籤中,您可以輸入短代碼,該短代碼將返回有關您當前類別頁面的一些信息。

通過使用特定的類,您可以將.box類設置爲顯示:無。

我希望這已經夠清楚了。

+0

我很抱歉地指出,這大多不值得一讀。 **頁面**模板的名稱出於某種原因。它們適用於頁面,而不是帖子。理論上,.box div可以被css隱藏,但即使如此,也必須根據類別給予額外的類或ID。這又會需要is_category條件標籤。用代碼示例證明我錯了,但是我沒有看到[shortcode](http://codex.wordpress.org/Shortcode_API)是如何實現這一點的。其實這個答案只值得讚揚,但我一天的表現太好了。 –