只在wordpress循环中显示特定类别?

问题描述:

如何仅在我的wordpress索引页面中显示特定类别?下面是我的主题代码...只在wordpress循环中显示特定类别?

此外,在网址为我的类别(如何我通常得到的ID)看时它似乎是一个奇怪的格式..

http://oil.wpengine.com/wp-admin/edit-tags.php?action=edit&taxonomy=category&tag_ID=1179&post_type=post

<?php query_posts(array ('Event_News' => 'event-news')); ?> 
    <?php if (have_posts()) : ?> 

    <ul class="posts"> 
 <li id="post-<?php the_ID(); ?>"> 

      <?php 
      get_the_image(array('size' => 'loop-main', 'width' => 160, 'height' => 120, 'before' => '<div class="cover">', 'after' => '</div>')); 
      ?> 

      <div class="postcontent"> 
       <h2><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2> 
       <div class="postmetadata"> 
        <ul> 
         <?php if (option::get('display_date') == 'on') { ?><li class="calendar"><time datetime="<?php the_time("Y-m-d"); ?>" pubdate><?php the_time("j F Y"); ?></time></li><?php } ?> 
         <?php if (option::get('display_author') == 'on') { ?><li class="author"><?php _e('By', 'wpzoom');?> <?php the_author_posts_link(); ?></li><?php } ?> 
         <?php if (option::get('display_category') == 'on') { ?><li class="category"><?php the_category(', '); ?></li><?php } ?> 
         <?php if (option::get('display_comments') == 'on') { ?><li class="comments"><?php comments_popup_link(__('0 comments', 'wpzoom'), __('1 comment', 'wpzoom'), __('% comments', 'wpzoom'), '', ''); ?></li><?php } ?> 
        </ul> 
       </div><!-- end .postmetadata --> 
       <?php the_excerpt(); ?> 
       <p class="more"><a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>" class="readmore" rel="nofollow"><?php _e('continue reading &raquo;', 'wpzoom');?></a> <?php edit_post_link(__('Edit this post', 'wpzoom'), ' | ', ''); ?></p> 
      </div><!-- end .postcontent --> 

      <div class="cleaner">&nbsp;</div> 
      <div class="sep">&nbsp;</div> 
     </li><!-- end #post-<?php the_ID(); ?> --> 
     <?php endwhile; // ?> 
    </ul> 

    <div class="cleaner">&nbsp;</div> 
    <?php else : ?> 

    <p class="title"><?php _e('There are no posts in this category', 'wpzoom');?></p> 

    <?php endif; ?> 

    <?php get_template_part('pagination'); ?> 

</div><!-- end .box --> 

您只需循环

query_posts(array ('category_name' => 'my-category-slug')); 
之前做query_post

如果你想帖子来自不止一个类别,那么你可以使用

query_posts('cat=8,4,3'); 

8,4,3都为3类

和循环使用后

wp_reset_query(); 

的ID欲了解更多详情,请查看此链接

http://codex.wordpress.org/Function_Reference/query_posts#All_Posts_in_a_Category

+0

谢谢!那么我会把它放在我的代码中? – js111 2013-02-22 05:54:20

+0

只是之前 如果(have_posts()): – 2013-02-22 06:09:08

+0

嗯似乎并没有工作,我更新的代码是正确的? – js111 2013-02-22 06:50:17