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

If / Else Causing Pagination Error WordPress

  • SOLVED

I am using an if else statement to load post custom excerpts in different formats according to their category. They load in the order they were posted but when i use pagination to get to the second page it starts over and displays the posts from the beginning again. The same happens on page 3 and so on.

Here is the link:

http://ibidprojects.com/home/

This is a simplified version of what i put in the loop:


<?php /* Start the Loop */ ?>
<?php query_posts($query_string . '&cat=5,1,6,7'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

<!------------------------ Two Columns Right Category ------------------------>

<?php if (in_category('two_columns_right') ): // we're in the two_columns_right category ?>



<!------------------------ Two Columns Left Category ------------------------>

<?php elseif (in_category('two_columns_left') ): // we're in the two_columns_left category ?>


<!------------------------ Two Columns Text Category ------------------------>

<?php elseif (in_category('two_columns_text') ): // we're in the two_columns_text category, two_columns_text ?>

<!------------------------ Single Column Category ------------------------>

<?php elseif (in_category('single_column') ): // we're in the two_columns_text category, two_columns_text ?>

<!------------------------ No Category ------------------------>

<?php elseif (in_category('artists') ): // we're in the two_columns_text category, two_columns_text ?>
<p>Hello Piers.</p>

<?php endif; // end the if, no images for other other categories ?>

<?php endwhile; ?>
<?php endif; ?>

<!------------------------ Navigation ------------------------>

<?php if ( $wp_query->max_num_pages > 1 ) : ?>
<div id="nav-below" class="navigation">
<div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">←</span> Older posts', 'twentyten' ) ); ?></div>
<div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">→</span>', 'twentyten' ) ); ?></div>
</div><!-- #nav-below -->
<?php endif; ?>


The full version here:

http://wordpress.pastebin.com/isN759a3

Answers (4)

2011-01-18

Utkarsh Kukreti answers:

Please add this before your query_posts call

<?php var_dump($query_string); ?>

Edit: Okay. make that

<?php global $query_string; ?> now.


Piers Rueb comments:

Still doesn't work, prints "NULL" at the top of the screen.


Piers Rueb comments:

That did it.


Piers Rueb comments:

Thanks.

2011-01-18

Kailey Lampert answers:

You need to pass the 'paged' argument to your query

<?php
$page = get_query_var( 'page' );
query_posts($query_string . '&cat=5,1,6,7&paged='.$page);
?>

2011-01-18

Andrzej answers:

do you have

global $query_string;

somewhere before "query_posts(" ?

2011-01-18

Jens Filipsson answers:

Change this:

<?php query_posts($query_string . '&cat=5,1,6,7'); ?>

With this:

<?php $page = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts($query_string . '&cat=5,1,6,7&paged=.$page'); ?>