If you would like to exclude one post from your blog, archive, search results or wherever you need to on your blog, you can do so by putting in a small piece of code within the particular WordPress loop:
The following example will show all posts except for the post with the ID of 179:
PHP:
-
<?php if (have_posts()) : while (have_posts()) : the_post(); if( $post->ID == '179' ) continue; ?>
-
<?php the_content();?>
-
<?php endwhile;endif;?>
This is something that I get a lot of requests for and is very useful in a number of situations.
If you ever need to exclude a single category from a WordPress page (archives, index, category page, etc) you can easily do so by using a little conditional tag code within the WordPress loop.
The example below will skip over any post that is in the category with the ID of 35:
PHP:
-
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
-
<?php if (in_category('35')) continue; ?>
-
<?php the_content(); ?>
-
<?php endwhile;endif;?>
This can be helpful if you want to not show a particular category in your blog (if you have a category based site setup) - or if you want to hide some categories from your search results.