Using WordPress ‘paginate_comments_links()’ PHP function

The paginate_comments_links() WordPress PHP function displays or retrieves pagination links for the comments on the current post.

Usage

paginate_comments_links( $args );

## Parameters
– `$args` (string|array) – Optional arguments. Default: array(). This parameter includes:
– `base` (string) – Base of the paginated URL.
– `format` (string) – Format for the pagination structure.
– `total` (int) – The total amount of pages. Default is WP_Query’s max_num_pages or 1.
– `current` (int) – The current page number. Default is ‘paged’ query var or 1.
– `aria_current` (string) – The value for the `aria-current` attribute. Default is ‘page’.
– `show_all` (bool) – Whether to show all pages. Default is false.
– `end_size` (int) – How many numbers on either the start and end list edges. Default is 1.
– `mid_size` (int) – How many numbers to either side of current pages. Default is 2.
– `prev_next` (bool) – Whether to include the previous and next links in the list. Default is true.
– `prev_text` (string) – The previous page text. Default is ‘« Previous’.
– `next_text` (string) – The next page text. Default is ‘Next »’.
– `type` (string) – Controls format of the returned value. Possible values are ‘plain’, ‘array’ and ‘list’. Default is ‘plain’.
– `add_args` (array) – An array of query args to add. Default is false.
– `add_fragment` (string) – A string to append to each link.
– `before_page_number` (string) – A string to appear before the page number.
– `after_page_number` (string) – A string to append after the page number.

More information

See WordPress Developer Resources: paginate_comments_links()

Examples

Display pagination links for comments with default settings.

paginate_comments_links();

Customize the previous and next text

Display pagination links with custom previous and next text.

paginate_comments_links( array(
  'prev_text' => 'Go back',
  'next_text' => 'Go forward'
) );

Display pagination links as an unordered list instead of plain text.

paginate_comments_links( array(
  'type' => 'list'
) );

Show all pages in the pagination

Display pagination links with all pages shown.

paginate_comments_links( array(
  'show_all' => true
) );

Display pagination links with a custom fragment appended to each link.

paginate_comments_links( array(
  'add_fragment' => '#comments-section'
) );