2013-10-23 32 views
0

我想顯示一些內容,具體取決於帖子的類別。 我的意思是 如果有人在「旅行」類別中閱讀帖子,我想要顯示一些與「 」相關的提示,如果屬於「遊戲」類別的其他內容。 我最好在側邊欄中需要這個。 有沒有插件?如果沒有,是否有可能經過一些修改的幫助下實現如何顯示類別/標籤特定內容

+1

有很多解決方案,這一點,因此提供了一個直接的答案是不是真的有可能。一個快速的谷歌也提出了很多方法,到目前爲止你有嘗試過什麼嗎? 最直接的是在編程的基礎上你的category.php/archive.php文件。 'get_query_var('cat');'會給你當前的類別ID。 –

回答

0

試試這個代碼:

只需用類別名稱等。無論您想更換「類別名稱」:

<?php query_posts('category_name=CATEGORYNAME&showposts=5'); 
while (have_posts()) : the_post(); 
    // do whatever you want 
?> 
<b><a href="<?php the_permalink() ?>" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a> 
<?php 
endwhile; 
?> 
0

試試這個:

<?php 

     $args2 = array(
      'numberposts' => 1, 
      'cat' => 4, 
      'orderby' => 'date', 
      'order' => 'DESC', 
      'post_type' => 'post', 
      'post_parent' => '', 
      'post_status' => 'publish', 
      'suppress_filters' => true 
     ); 
     $homepage_content = get_posts($args2); 

     foreach ($homepage_content as $key => $value) { 
      echo "<h2>" . $value->post_title . "</h2>"; 
      echo $value->post_content; 
      $post_id = $value->ID; 
     } 

?> 

這裏只是在cat參數中傳遞Category的ID。

For more reference: http://codex.wordpress.org/Template_Tags/get_posts 

- 感謝