在wordpress主循环中过滤掉指定类别中的帖子


/ Published in: PHP
Save to your folder(s)

Exclude Posts From Some Category
这样就可以在首页中不显示某些类别(比如asides)的帖子了


Copy this code and paste it in your HTML
  1. <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
  2.  
  3. <!-- If the post is in the category we want to exclude, we simply pass to the next post. -->
  4. <?php if (in_category('3')) continue; ?>
  5.  
  6. <div class="post">
  7.  
  8. <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
  9.  
  10. <small><?php the_time('F jS, Y'); ?></small>
  11.  
  12. <div class="entry">
  13. <?php the_content(); ?>
  14. </div>
  15.  
  16. <p class="postmetadata">Posted in <?php the_category(', '); ?></p>
  17. </div> <!-- closes the first div box -->
  18.  
  19. <?php endwhile; else: ?>
  20. <p>Sorry, no posts matched your criteria.</p>
  21. <?php endif; ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.