在我的wp主题中,我的帖子数量相当于每页2个(例如),我有3个帖子,所以前2个帖子必须显示在第1页,最后一个帖子显示在第2页,页面总数必须为2(我猜),但有6页,我不明白为什么。有循环和分页的代码:
<?php
echo '<div class="news-block">';
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$query = new WP_Query(array('category_name' => 'news', 'showposts' => '2', 'paged' => $paged) );
if (have_posts() ) :
while ( have_posts()) : the_post() ;
echo '<div class="news-column">';
echo '<div class="news-img column">';
echo '<div class="news-date">'. get_the_time('j M Y') . '</div>';
echo '</div>' ;
echo '<div class="news-content column">';
echo '<div class="news-title">' . get_the_title() . '</div>';
echo the_excerpt() . '</div>';
echo '</div>';
endwhile;
echo '</div>';
echo '<div class="pagination-list">';
previous_posts_link('<i class="fa fa-caret-left"></i>');
wp_pagenavi();
next_posts_link('<i class="fa fa-caret-right"></i>');
echo '</div>';
endif;
wp_reset_postdata();
?>