-1

I am having an issue where I wanted to strip out all categories but one from the homepage so I added the following to the loop:

query_posts('cat=2');

However now the issue is that page one of the homepage is fine, however if you use the pagination at the bottom and select page 2 it will reproduce the exact articles on the homepage e.g.

http://alumen.s.strategiesuk.net/ - Home page
http://alumen.s.strategiesuk.net/page/2/ - 2nd page of Home

Any help on the subject would be greatly appreciated.

(I am using the theme Gonzo)

1 Answers1

0

Use this in your child themes functions.php file

add_action( 'pre_get_posts', 'exclude_category_posts' );

function exclude_category_posts( $query ) {

if( $query->is_main_query() && $query->is_home() ) {

$query->set( 'cat', '-27,-30' );
    }
}

Add a comma separated list of category i.d's to the set.

Never Use Query Posts

Brad Dalton
  • 6,985
  • 2
  • 36
  • 47