Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/252.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 博客页面上的分页显示每个页面的相同帖子_Php_Wordpress_Pagination - Fatal编程技术网

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

Php 博客页面上的分页显示每个页面的相同帖子,php,wordpress,pagination,Php,Wordpress,Pagination,我在一个页面上显示博客文章,并已启用分页。然而,分页似乎并不十分有效。 当您导航到第二页时,它将显示与第一页相同的帖子。 这是我的代码: <div class="container-max"> <?php $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : '1'; ?> <?php $args = array( 'numberposts' =>

我在一个页面上显示博客文章,并已启用分页。然而,分页似乎并不十分有效。 当您导航到第二页时,它将显示与第一页相同的帖子。 这是我的代码:

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

你知道我做错了什么吗?

你能用查询帖子吗

$postslist = get_posts( $args );
替换

$postslist = query_posts( $args );

将'numberposts'=>5替换为'posts\u per\u page'=>5

args数组中的'numberposts'=>5是什么?页面上显示的帖子数量您应该写入'posts\u per\u page'=>5,您确定cat ID为负数吗?是否每次在select查询中使用'limit startnum,countnum'?!