I’m trying to determine if there’s more than one page of comments in single.php.
In archive.php I can do something like this to check if there’s more than one page of posts:
if ( $wp_query->max_num_pages > 1 ) {
// There's more than one page of posts in this archive.
}
As far as I can tell, this doesn’t work for comments. How can I check if comments are paginated in single.php?
Just some additional info for the main comment query:
Since you mentioned the global $wp_query
object, we can see that it stores:
$wp_query->max_num_comment_pages = $comment_query->max_num_pages;
in the main comment query in the comments template.
There exists a wrapper for this, namely:
get_comment_pages_count();
that’s available after the main comment query.
If we need it before the main comment query runs, then we might check if
get_comments_number( $post_id )
is greater than get_option( 'comments_per_page' )
. But we should keep in mind that the comments_per_page
parameter can be modified through e.g. the comments_template_query_args
filter.