Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Exclude categories from loop and pagination problems WordPress


I have three loops, one in the main column, and two in the right sidebars. Via the theme options page the user can decide which categories of posts to show in the sidbar loops while the loop in the main column is to show all latest posts except from the two selected categories.

Problem 1: The main column loop only excludes the posts from selected category in one of the sidebars. The other still shows in the main loop.

Problem 2: During all this loop fixing, the pagination (link to Older Posts furthest down), doesn't work.

Send me an email to [email protected] and I'll send the login details.

Answers (5)


Sébastien | French WordpressDesigner answers:

in the file myhome.php

<?php $exc = get_category_id ( ( get_option('mmcp_sidecat') ? get_option('mmcp_sidecat') : 'uncategorized') ); ?>

<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts('cat=-'.$exc.'&posts_per_page=5&
paged=' . $paged); ?>


$exc = get_category_id ( ( get_option('mmcp_sidecat') ? get_option('mmcp_sidecat') : 'uncategorized') );
$exc_two = get_category_id ( ( get_option('mmcp_sidecat2') ? get_option('mmcp_sidecat2') : 'uncategorized') ); ?>

<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts('cat=-'.$exc.',-'.$exc_two.'&posts_per_page=5&
paged=' . $paged); ?>

Sébastien | French WordpressDesigner comments:

about the pagination
<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts('cat=-'.$exc.'&posts_per_page=5&paged=' . $paged); ?>


<?php $page = get_query_var( 'page' );
query_posts('cat=-'.$exc.'&posts_per_page=5&paged=' . $page); ?>

Sébastien | French WordpressDesigner comments:

I have edit the first message because the line which start by "$exc_two" must use mmcp_sidecat2 (and no mmcp_sidecat)
it's very important :-)


Oleg Butuzov answers:

sent details. from email [email protected]


David Navarrete answers:

you can try with this type of loop?

<?php $query = new WP_Query(array('category__not_in' => array(1,2,3), 'showposts' => 10 )); ?>
<?php if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); ?>


Marvin Shaker answers:

Add <?php wp_reset_query(); ?> After Each Loop


Chris Lee answers:

You could just install Advanced category excluder to solve this: