正如我在评论中所说的,
您需要使用get_option( \'posts_per_page\' )
和get_query_var( \'paged\' )
计算您的帖子编号
您可以执行以下操作:(我对代码进行了注释,使其易于理解。这将进入函数。php)
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;
}
然后,您可以在模板中按如下方式使用它来显示正确的帖子编号(
您需要使用这个inside 回路)
echo get_post_number();