Wordpress - 帖子页面显示相同的5个帖子

时间:2013-08-29 21:42:18

标签: php wordpress

所以一直在玩相同的WordPress主题设置和代码几个小时,似乎无法解决我的问题。每个页面显示相同的5个帖子。我使用的是模板页面上标准的相同代码,但它没有被更改。有没有简单的方法来修改它,以便每个页面将显示不同的5个帖子而不是相同的帖子。我试图修改的页面是:showposts.php

我认为需要修改的代码如下:

<?php
  $recentPosts = new WP_Query( array( 'cat' => 3, 'posts_per_page' => 5, 'paged' => get_query_var('paged'), 'offset' => 1) );
?>
<?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?>
<div class="entry-title">
<a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a>
</div>
<?php the_excerpt(); ?>
<?php endwhile; ?>

希望有人能让我知道我哪里出错了。我已经搜索了这里发布的一些问题,但只看到了修改过的代码,并且没有线索从哪里开始或放在哪里。

任何帮助表示赞赏。谢谢!

1 个答案:

答案 0 :(得分:0)

你可以尝试这个(删除偏移量)

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$recentPosts = new WP_Query( array( 'cat' => 3, 'posts_per_page' => 5, 'paged' => $paged) );

More on Codex.