获取当前页面中 post 的总数

Getting total number of post in current page

我试图在使用分页时显示当前页面中 post 的数量。在我使用的所有页面中,总共 posts $query->found_posts;。但是,我不知道如何在每页上计算 post 。例如,我想显示 Showing 5 of 50 posts 知道吗? 提前致谢。

found_posts类似,还有post_count,表示“当前查询的帖子数”。所以你可以使用 $query->post_count.

参考:https://github.com/WordPress/wordpress-develop/blob/0ea7a38664746f9ad4f402768975c66928817531/src/wp-includes/class-wp-query.php#L100