MariaL
MariaL

Reputation: 1242

Pagination on blog page shows same posts for each page

I'm displaying blog posts on a page and have enabled pagination. However, the pagination doesn't seem to quite work. When you navigate to the second page it displays the same posts as on the first page. This is my code:

<div class="container-max">
       <?php $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : '1'; ?>
        <?php 
$args = array( 'numberposts' => 5, 'offset' => 2, 'post_status'=>"publish",'post_type'=>"post",'orderby'=>"post_date",'cat'=>'-8, -9, -7, -6, -5, -4','paged'=> $paged);
$postslist = get_posts( $args );
echo '<div class="latest_new_posts main-news">';
?>

 <?php 
     $wp_query = new WP_Query($args);
    ?>

    <?php if ( $wp_query->have_posts() ) : ?>
    <?php while ( $wp_query->have_posts() ) : the_post(); ?>   
<?php foreach ($postslist as $post) :  setup_postdata($post); ?> 
 <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12" style="position:relative; margin:45px 0;" >
     <div class="blog-date-news main-news-date"><span><?php the_date('d/m/Y'); ?></span></div>
     <div class="blog-container main-news-container">
     <div class="news-blog-title"><span><?php the_title(); ?></span></div>
     <div class="news-blog-excerpt"> <?php echo excerpt(500); ?> </div>
     <div class="news-blog-more main-news-blog-more"><a href="<?php the_permalink(); ?>"> <img src="http://www.mariadev.co.uk/wp-content/uploads/2017/05/read-more.png"/></a></div>
</div>
    </div>
<?php endforeach; ?>

    <?php endwhile; ?>

 <div class="blog-page-next"><?php next_posts_link( 'Next', $wp_query->max_num_pages );
             ?> </div>

     <?php wp_reset_postdata(); ?>
    <?php else : ?>
    <p><?php __('No News'); ?></p>
    <?php endif; ?>

    </div>
</div>

Any ideas what I'm doing wrong?

Upvotes: 0

Views: 139

Answers (2)

Sanjay
Sanjay

Reputation: 390

Replace 'numberposts' => 5 with 'posts_per_page' => 5

Upvotes: 1

Can you use query_posts() ?

$postslist = get_posts( $args );

replace

$postslist = query_posts( $args );

Upvotes: 0

Related Questions