Search Blog Posts

Excluding Posts from the Index Page on Wordpress

If you have ever wanted to exclude posts from your homepage on wordpress keep reading…..

Excluding posts on the index page of the blog was one of those things that i knew was possible but never really got around to actually doing it!

I thought i would share the solution to the problem as i managed to find a quick and easy way of excluding the posts.

Here’s how you do it

Step 1
Locate the index.php file in your current active theme. This is usually situated in the ‘wp-content/themes/’ folder of your server. Once you have located this folder pick your current theme and look inside to find the index.php file. You will then need to download this file and open in your default editor.

Step 2
Once you’ve managed to open the file do a search for the following line of code:
<?php while (have_posts()) : the_post(); ?>

You will then need to insert the following code so you have something that looks like this:
<?php while (have_posts()) : the_post(); ?>
<?php if (in_category('79')) continue; ?>

Step 3
Notice that the category 79 has been used in this example.
To find the id of the category that you want to exclude from the homepage simply login to your admin page and head over to the manage > categories section. Once there simply mouse over the category name that you wish to exclude and notice in the url there will be an id number (this normally displayed to the bottom of your browser).

Extra Steps
If you want to exclude multiple categories simply duplicate the same line of code as shown above changing the id number. See the example below:

<?php while (have_posts()) : the_post(); ?>
<?php if (in_category('79')) continue; ?>
<?php if (in_category('29')) continue; ?>
<?php if (in_category('30')) continue; ?>
<?php if (in_category('12')) continue; ?>

This is its as simple as that!

Tags: , , ,

Post this story to Delicious Post this story to Digg Post this story to Technorati Post this story to SumbleUpon Post this story to Facebook Post this story to Reedit

2 Comments to “Excluding Posts from the Index Page on Wordpress”

  1. Steve Says:

    Brilliant worked fine for me :) thanks

  2. Aleksey Says:

    It Works ! Thanks a lot. I tryed 3 or 4 similar ways, but they didn’t work, don’t know why. That works fine even with version 2.6.1. Thanks a lot again!

Leave a Comment

  1. XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

© Copyright 2003-2008 Minimalistic Designs | Terms | Links | Sitemap
Website Design Liskeard - www.minimalistics.co.uk