您可以计算offset
通过paged
和posts_per_page
. E、 g:
$per_page = 6;
$paged = get_query_var(\'paged\') ? : 1;
$offset = (1 === $paged) ? 0 : (($paged - 1) * $per_page) + (($paged - 1) * 2);
$args = array(
\'order\' => \'ASC\',
\'paged\' => $paged,
\'offset\' => $offset,
\'orderby\' => \'ID\',
\'post_type\' => \'post\',
\'post_status\' => \'publish\',
\'posts_per_page\' => $per_page,
\'ignore_sticky_posts\' => 1
);
$query = new WP_Query($args);
while ( $query->have_posts() ) : $query->the_post();
echo get_the_title() . \'<br>\';
endwhile;
previous_posts_link(\'« Previous\', $query->max_num_pages);
if ($paged > 1) echo \' | \';
next_posts_link(\'More »\', $query->max_num_pages);
echo \'<br> Showing \' . $offset . \'-\' . ($offset + 6) . \' of \' . $query->found_posts . \' posts.\';
wp_reset_postdata();
请注意,循环从索引0开始,因此如果我们忽略粘性帖子,并且每页仅显示6篇帖子,那么第2页上的结果应该是8-14,而不是您所期望的9-14。