我不能在我的主页代码上进行分页。它一直在显示相同的帖子

时间:2011-10-19 作者:megan

有人能告诉我我的代码有什么问题吗?为什么它总是在分页的页面上显示相同的内容?

它有两个循环。。首先是针对特色帖子,然后是其他帖子。

<?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>

1 个回复
SO网友:Ijaas

将$postArgs更改为:

$postArgs = array(\'post_type\' => \'post\', \'paged\' => $paged);
数组中的所有其他内容都是默认的,不必要的。

同时添加$the\\u query->revend\\u posts();第一次结束后;

Update

修复分页问题:

global $wp_query;
$paged = ($wp_query->query[\'paged\']) ? $wp_query->query[\'paged\'] : 1;

结束

相关推荐

Broken category pagination

出于某种原因,下面的代码一直工作到我到达第三页并给出404。不使用任何插件就可以修复它吗?<?php $temp = $wp_query; $wp_query = null; $wp_query = new WP_Query(\'cat=\'. $id .\'&posts_per_page=4&paged=\'.$paged); while ($wp_query->have_posts()) : $wp_query