简体   繁体   中英

How do I display posts excluding one category on blog home page?

I want my home page to display posts from all categories except one called "music". And I don't want the link to change. How can I hook into the "Front page" or "Posts page" results and filter out one category?

I am assuming I must make some call to the Wordpress API.

Thanks!

 <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

 <!-- If the post is in the category we want to exclude, we simply pass to the next post. -->
 <?php if (in_category('3')) continue; ?>

 <div class="post">

  <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>

  <small><?php the_time('F jS, Y'); ?></small>

  <div class="entry">
    <?php the_content(); ?>
  </div>

  <p class="postmetadata">Posted in <?php the_category(', '); ?></p>
 </div> <!-- closes the first div box -->

 <?php endwhile; else: ?>
 <p>Sorry, no posts matched your criteria.</p>
 <?php endif; ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM