你应该可以从相同的$wp_query
对象:
global $wp_query;
$num_pages = $wp_query->found_posts;
$num_pages
将包含与您的类别(或您使用的任何其他标准)匹配的总计数。
如果您只是想得到一个可以显示的字符串,那么这个修改后的函数版本就可以了。
function get_post_number()
{
global $wp_query;
/*
* Get current page number. Set page 1 to one as get_query_var( \'paged\' ) will be 0
*/
$current_page_number = get_query_var( \'paged\' ) ? get_query_var( \'paged\' ) : 1;
/*
* Get the posts_per_page option that is set under "Reading"
*/
$posts_per_page = get_option( \'posts_per_page\' );
/*
* Get the current post position in the loop, add 1 because the counter starts at 0
*/
$current_post_position = $wp_query->current_post + 1;
/*
* If this is page one, return the post position as is
*/
if ( $current_page_number == 1 )
return $current_post_position;
/*
* Calculate the post number on paged pages
*/
return ( ( $posts_per_page * ( $current_page_number - 1 ) ) + $current_post_position ). \'/\' . $wp_query->found_posts;
}