From only one category in WordPress home page

It’s something simple, but may still take hours if we don’t know what to do exactly. To repeat, we want posts from only a specific category to be echoed in the home page.

Note: File to change > wp-content/themes/your template/index.php

Step I: Find the loop, it looks like:

1
while (have_posts()) : the_post();

Step II: Replace this by:

1
2
if ( is_home() ) { query_posts($query_string . '&cat=3'); } 
while (have_posts()) : the_post();

In the example above, it is assumed that 3 is the only category that we want to show in the home page.

Alternatively, if 3 is the only category we DO NOT want to have in our word press home page, the same code will be:

1
2
if ( is_home() ) { query_posts($query_string . '&cat=-3'); } 
while (have_posts()) : the_post();