0

I have a static page which runs two loops but pagination doesn't work on the second loop.

  1. The first loop shows the static content of the page
  2. The second loop shows the last 3 blog posts

Pagination shows up, adds /page/2 to the url but it always shows just the same 3 posts. Why doesn't this work as expected?

First loop: display the static content

if (have_posts()) : while (have_posts()) : the_post();
    the_content('<p class="serif">Read the rest of this page &raquo;</p>'); ?>
endwhile; endif;

Second loop: shows the last 3 posts and pagination

global $more;
$more = 0;
$temp = $wp_query;
$wp_query= null;

$wp_query = new WP_Query();
$wp_query->query(array('post_type'=>'post','post_status'=>'publish','showposts'=>3,'paged'=>$paged));

while ($wp_query->have_posts()) : $wp_query->the_post();
    the_content();
endwhile;

next_posts_link();
previous_posts_link();

1 Answer 1

1

You aren't setting the $paged variable, at least not in the code posted.

Per the Codex, you need to do something like this:

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

... before trying to use the $paged variable. That is, it needs to come before this line:

 $wp_query->query(array('post_type'=>'post','post_status'=>'publish','showposts'>3,'paged'=>$paged));

Also, side note, what is this-- php the_content(); ? That is going to trigger an error. Why do you have the php there?

1
  • thank you, I removed the "php".I've added that code and yes, I forgot it but it doesn't work either. The url on the pagination element remains /page/2 but it just doesn't work! Apr 5, 2013 at 14:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.