简体   繁体   中英

Wordpress Pagination showing same posts on all pages

On this page here , I'm using the following php code to show the posts:

<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts($args);
if( have_posts() ) :?>

<?php twentyeleven_content_nav( 'nav-above' );?>
<?php
$withThumb = 5; 
while ( have_posts() ) : the_post();
if ($withThumb-- > 0) { ?>
    <div class="post-thumb-title">
        <a href="<?php the_permalink() ?>"><?php the_post_thumbnail(array(632,305));?></a>
        <p class="thumb-title2"><?php the_title(); ?></p>
        <p class="news-date"><?php the_time('F jS, Y') ?></p>
        <div id="post-excerpt">
            <?php the_excerpt(); ?>
        </div>
    </div>
<?php } else { ?>
    <div class="post-title">
        <p class="thumb-title2">
            <a href="<?php the_permalink() ?>"><?php the_title(); ?></a>
        </p>
    </div>
<?php } ?>
<?php endwhile; ?>
<?php twentyeleven_content_nav( 'nav-below' ); ?>

The issue is that if you click on " Older Posts ", it shows the same posts and not the older ones.

It does the same when you open the 3rd page, 4th page and so on.

How do I fix this?

Thanks

You need to add the page number to the arguments of the query_posts() call.

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args['paged'] = $paged;
query_posts($args);

See the documentation .

Note: If you've already defined $args and as a string not an array, you'll want to concatenate &paged=page_number_here , instead of adding a new key-value pair.

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