【发布时间】:2017-06-01 18:30:44
【问题描述】:
我正在页面上显示博客文章并启用了分页。但是,分页似乎不太有效。 当您导航到第二页时,它会显示与第一页相同的帖子。 这是我的代码:
<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>
任何想法我做错了什么?
【问题讨论】:
-
args 数组中的
'numberposts' => 5是什么? -
页面显示的帖子数
-
你应该写
'posts_per_page' => 5,你确定猫 ID 是负数吗? -
您是否每次都在选择查询中使用 'limit startnum , countnum' ?!
标签: php wordpress pagination