Exclude Category

This is the code I got to work after realizing that the code I was using broke the pagination.

<?php if ( is_home() ) {
$paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1;
query_posts(‘cat=-21&paged=’.$paged); } ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

The code below worked part way, but like I said it broke the pagination.


This is the code I thought was working <?php if ( is_home() ) { query_posts( ‘cat=-21’ ); } ?>

I put it right before the start of the loop before this code <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

HOWEVER

I also found that you can use WP_query. The code for that way looks like this:

<?php $the_query = new WP_Query( ‘cat=-21’ ); ?>

<?php if (have_posts()) : ?>

<?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>

Leave a Reply