博客页面上的分页显示每个页面的相同帖子

时间:2017-05-31 17:41:48

标签: php wordpress pagination

我在页面上显示博客帖子并启用了分页功能。但是,分页看起来并不合适。 导航到第二页时,它会显示与第一页相同的帖子。 这是我的代码:

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

任何想法我做错了什么?

2 个答案:

答案 0 :(得分:0)

你能使用query_posts()吗?

$postslist = get_posts( $args );

替换

$postslist = query_posts( $args );

答案 1 :(得分:0)

'numberposts' => 5替换为'posts_per_page' => 5