Code Snippet

Home » Code Snippets » WordPress » Remove Specific Categories From The Loop

Remove Specific Categories From The Loop

<?php query_posts('cat=-3'); ?>

<?php if (have_posts()) : ?>

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

		<h3></h3>

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

		<?php the_content(); ?>

<?php endwhile; ?>

The area inside the while loop could be anything, that's just some example typical inside-loop code. The trick is the first line, and the cat=-3 parameter. "-3" in this case is the ID of the category, and you can replace that with any category you wish to remove from the loop. You may use comma separated values here to remove more than one category (e.g. cat=-1,-2).

Subscribe to The Thread

  1. Filipe

    I use that so i can have 2 pages that display different posts one display the news and the other my latest work everything works fine but for some reason the read more button does not appear any suggestions thanks

    • Hi

      Do you know how to code this if you used /work/ instead of an id.

      Thanks

  2. i use it within looping. is it ok?

    • here..

      
       <?php if (have_posts()) : ?>
       <?php query_posts($query_string.'&cat=-70'); while (have_posts()) : the_post(); ?>
      
      - - -  content - - -
      
      <?php endwhile; ?>
      <?php wp_pagenavi(); ?>
      <?php else : ?>
      <?php include(TEMPLATEPATH . '/404.php'); ?>
      <?php endif; ?>
      

      because i’m using wp_pagenavi… is it ok?

Speak, my friend

At this moment, you have an awesome opportunity* to be the person your mother always wanted you to be: kind, helpful, and smart. Do that, and we'll give you a big ol' gold star for the day (literally).

Posting tips:
  • You can use basic HTML
  • When posting code, please turn all
    < characters into &lt;
  • If the code is multi-line, use
    <pre><code></code></pre>
Thank you,
~ The Management ~