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.

Please can someone tell me what is wrong with my code and why it keeps showing the same content on the paginated pages?

It has two loops.. the first is for the featured post and then the rest of the posts.

<?php 
 $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
  $postArgs = array(
      'showposts' => get_option('posts_per_page'),
      'offset' => 0,
      'orderby' => 'post_date',
      'order' => 'DESC',
      'post_type' => 'post',
      'post_status' => 'publish',
      'paged' => $paged);
  $the_query = new WP_Query( $postArgs );
?>
<div id="billboard">
  <?php
    $a = 0;
    while ( $the_query->have_posts() ) : $the_query->the_post();
      if ($a == 0)
      { ?>
<!-- post image -->
<div id="mainPostImage">
    <div class="inner">


        </div>
</div>
<!-- close post image --> 

        <div id="mainPostDetail">
          <div class="content">
            <h2><?php the_title(); ?></h2>
            <h3>by <?php the_author(); ?> on <?php the_time('F jS, Y'); ?></h3>
            <div class="entry-content"><?php the_excerpt(); ?></div>
          </div>
        </div>
      <?php } else {
        break;
      }
      $a++;
    endwhile;
  ?>
</div>

<div id="mainContent">
  <div id="primary">
    <div class="posts">
    <?php
      $b = 0;
      while ( $the_query->have_posts() ) : $the_query->the_post();
        if ($b > 0) { ?>
          <div class="post">
            <span class="post-thumbnail">

        </span>
            <h2><?php the_title(); ?></h2>
            <h3>by <?php the_author(); ?> on <?php the_time('F jS, Y'); ?></h3>
            <div class="entry-content"><?php the_excerpt(); ?></div>
            <div class="entry-meta">
              <?php comments_number( '', 'one Comment', '% Comments' ); ?>
            </div>
          </div> <!-- .post -->
        <?php }

        $b++;
      endwhile;
?>

<div class="nextprev">
<div style="float:right;"><?php next_posts_link('Older Entries  &raquo;', $the_query->max_num_pages) ?></div>
<?php previous_posts_link('&laquo; Newer Entries &raquo;') ?>
</div>

<?php
if($the_query->max_num_pages>1){?>
    <p style="text-align:right;">
    <?php
      if ($paged > 1) { ?>
        <a href="<?php echo '?paged=' . ($paged -1); //prev link ?>"><</a>
                        <?php }
    for($i=1;$i<=$the_query->max_num_pages;$i++){?>
        <a href="<?php echo '?paged=' . $i; ?>" <?php echo ($paged==$i)? 'class="selected"':'';?>><?php echo $i;?></a>
        <?php
    }
    if($paged < $the_query->max_num_pages){?>
        <a href="<?php echo '?paged=' . ($paged + 1); //next link ?>">></a>
    <?php } ?>
    </p>
<?php } ?> 

<?php      wp_reset_postdata();
wp_reset_query();
?> 
</div>
share|improve this question

1 Answer 1

Change $postArgs to:

$postArgs = array('post_type' => 'post', 'paged' => $paged);

Everything else in the array u have up there is default and unnecessary.

Also add $the_query->rewind_posts(); after the first endwhile;

Update

Fix for pagination issues:

global $wp_query;
$paged = ($wp_query->query['paged']) ? $wp_query->query['paged'] : 1;
share|improve this answer
    
Ijaas thank you for your reply!! I made the changes which solved the problem of not displaying all the posts on the home page but the pagination is still not working.. still loads same content :( –  megan Oct 19 '11 at 11:04
    
Ok try this $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; echo $paged; die(); now try going to ?paged=2 and if the site is catching the paged variable correctly you should just see the number 2. if not it think we will need to dig deeper. –  Ijaas Oct 20 '11 at 8:45
    
ok seems wordpress isn't saving the paged value for some reason, so see the update i made to my original answer to fix the problem. –  Ijaas Oct 20 '11 at 8:58
    
The solutions works and I'm temporarily greatful for that but it's ugly, globals always are. –  markus-tharkun Oct 7 '12 at 13:39

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.