Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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();
share|improve this question
add comment

1 Answer

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?

share|improve this answer
    
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! –  Andrea Puiatti Apr 5 '13 at 14:10
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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