统计单个wordpress id被<!——nextpage——>分割的页面总数


Count total number of pages a single wordpress id has been split with <!--nextpage-->

如何使用以下方法计算wordpress帖子或页面被分成多个页面的总页数:

<!--nextpage-->

我可以很容易地得到当前页码:

$pagenumber = get_query_var( 'page', 1 );

但是,我怎么得到总数呢?

正如源帖子所描述的:

你可以使用插件,或者我更喜欢手工编码的方式。

<?php
echo $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish'");
?>
插件https://wordpress.org/plugins/post-count/

来源:https://wordpress.org/support/topic/show-number-of-post?replies=4

<?php the_posts_pagination( array(
'mid_size' => 2,
'prev_text' => __( 'Back', 'textdomain' ),
'next_text' => __( 'Onward', 'textdomain' ),
) ); ?>