the_comments_pagination()WP 4.4.0

Outputs a block of pagination links for the comments pages of a post.

Will not output anything if the post does not have enough comments to be split into pages.

This is a wrapper for the function get_the_comments_pagination()

No Hooks.

Returns

null. Nothing. Outputs HTML code.

Usage

<?php the_comments_pagination( $args ); ?>
$args(array)

Parameters that shape the output. Default parameters passed:

$defaults = array(
	'screen_reader_text' => __( 'Comments navigation' ),
	// from the function paginate_comments_links():
	'base'    => add_query_arg( 'cpage', '%#%' ),
	'format'  => '',
	'total'   => $max_page,
	'current' => $page,
	'echo'    => true,
	'add_fragment' => '#comments'
);

Also, can accept parameters that are passed to the function paginate_links()

Default: array()

Examples

0

#1 Output pagination of comments posts (demo)

Let's assume that the post has 300 comments. The setting is to output 100 per page. Let's display pagination links:

<?php the_comments_pagination(); ?>

As a result, this code will output:

<nav class="navigation comments-pagination" role="navigation">

	<h2 class="screen-reader-text">Comments Navigation</h2>

	<div class="nav-links">
		<a class="prev page-numbers" href="http://example.com/postname/comment-page-1/#comments">← Earlier</a>
		<a class="page-numbers" href="http://example.com/postname/comment-page-1/#comments">1</a>
		<span class="page-numbers current">2</span>
		<a class="page-numbers" href="http://example.com/postname/comment-page-3/#comments">3</a>
		<a class="next page-numbers" href="http://example.com/postname/comment-page-3/#comments">Further →</a>
	</div>

</nav>

Changelog

Since 4.4.0 Introduced.

the_comments_pagination() code WP 6.9

function the_comments_pagination( $args = array() ) {
	echo get_the_comments_pagination( $args );
}