2012-02-08 130 views
0

這似乎是一件應該很容易的事情,我希望在新聞發佈時輸出事件帖子和最新三個新聞項目的最新三個事件,我有這個工作在一個非常基本的意義,但我可以制定如何做到以下幾點:WordPress的 - 在所有帖子上輸出sidebar.php中的相關帖子

當在事件中的帖子顯示最新的三個事件,當在新聞節目中發佈最新的三個新聞帖子。我在這裏看到http://codex.wordpress.org/Conditional_Tags,並認爲is_category('news')和is_category('events')可以做到這一點,但是這些條件似乎只在類別歸檔頁面上可用。

目前,我有下面的代碼你是一個單一的帖子頁面上簡單的檢查,(我只使用了新聞和事件的帖子,一切是一個頁面):

<?php 
    if (is_single()) { 
    query_posts('category_name=news&order=DSC&offset=1&orderby=ID&posts_per_page=2'); 
    if (have_posts()) : while (have_posts()) : the_post(); ?> 

    <article> 
     <h3><a href='<?php the_permalink() ?>'><?php the_title(); ?></a></h3> 
     <span class="date"><?php the_time(get_option('date_format')); ?></span> 
     <?php the_excerpt($strip_teaser); ?> 
     <a class="more" href='<?php the_permalink() ?>'>Read more</a> 
    </article> 

    <?php endwhile; endif; wp_reset_query();?> 

    <?php 
    } 
    else { 

    } 

    ?> 

回答

相關問題