简体   繁体   中英

Wordpress - Posts Page shows same 5 posts

So been playing with same WordPress theme settings and code for a few hours and can't seem to solve an issue I have. Each page shows the same 5 posts. I'm using the same code that is standard on the template page and it hasn't been altered. Is there any easy way to modify it so that each page will display a different 5 posts rather than the same ones. The page I'm trying to modify is: showposts.php

I think the code that needs to be modified is the following:

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

Hoping someone can let me know where I'm going wrong. I've searched through some of the questions posted on here but only seen modified code and haven't a clue where to start or where to put it.

Any help appreciated. Thanks!

You may try this (remove the offset)

$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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM