2012-02-08 90 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 { 

    } 

    ?> 

回答

相关问题