我试图在使用分页时实现以下搜索结果计数;
Showing 1-9 of 368 Items - (第一页)
Showing 9-18 of 368 Items - (第二页)
但我正在让自己$count_posts;
我不确定我是否完全掌握了它/
<小时/>
PHP (Search.php)
<?php $post_count = $wp_query->post_count; ?>
<?php $count_products = wp_count_posts( \'products\' )->publish; ?>
<?php $count_posts = wp_count_posts()->publish; ?>
HTML/PHP (Search.php)
<p class="small text-uppercase">Showing <?php echo $post_count; . \'-\' . $post_count; ?> of <strong><?php echo $count_products ?> items</strong></p>
我的问题是:我怎样才能达到我所追求的结果?
EDIT: 7月4日14:56
经过一段时间的测试,我在@KrzysiekDródż的帮助下找到了答案。
if ( !is_paged() ) {
// first page of pagination
$first_post = absint( $wp_query->get(\'paged\') - 1 );
$last_post = $first_post + $wp_query->post_count - 1;
$all_posts = $wp_query->found_posts;
} else {
$first_post = absint( $wp_query->get(\'paged\') - 1 ) * $wp_query->get(\'posts_per_page\') + 1;
$last_post = $first_post + $wp_query->post_count - 1;
$all_posts = $wp_query->found_posts;
}