On this page
paginate_comments_links( string|array $args = array() ): void|string|array
Displays or retrieves pagination links for the comments on the current post.
Description
See also
Parameters
$argsstring|array Optional-
args. See paginate_links() .
More Arguments from paginate_links( ... $args )
Array or string of arguments for generating paginated links for archives.
basestringBase of the paginated url.formatstringFormat for the pagination structure.totalintThe total amount of pages. Default is the value WP_Query'smax_num_pagesor 1.currentintThe current page number. Default is'paged'query var or 1.aria_currentstringThe value for the aria-current attribute. Possible values are'page','step','location','date','time','true','false'. Default is'page'.show_allboolWhether to show all pages. Default false.end_sizeintHow many numbers on either the start and the end list edges.
Default 1.mid_sizeintHow many numbers to either side of the current pages. Default 2.prev_nextboolWhether to include the previous and next links in the list. Default true.prev_textstringThe previous page text. Default '« Previous'.next_textstringThe next page text. Default 'Next »'.typestringControls format of the returned value. Possible values are'plain','array'and'list'. Default is'plain'.add_argsarrayAn array of query args to add. Default false.add_fragmentstringA string to append to each link.before_page_numberstringA string to appear before the page number.after_page_numberstringA string to append after the page number.
Default:
array()
Return
void|string|array Void if 'echo' argument is true and 'type' is not an array, or if the query is not for an existing single post of any post type.
Otherwise, markup for comment page links or array of comment page links, depending on 'type' argument.
More Information
Defaults
$args = array(
'base' => add_query_arg( 'cpage', '%#%' ),
'format' => '',
'total' => $max_page,
'current' => $page,
'echo' => true,
'add_fragment' => '#comments'
);
Arguments passed in are merged to the defaults, via wp_parse_args() .
These arguments are mostly to make the call of paginate_links() work, so be careful if you change them.
Source
File: wp-includes/link-template.php. View all references
function paginate_comments_links( $args = array() ) {
global $wp_rewrite;
if ( ! is_singular() ) {
return;
}
$page = get_query_var( 'cpage' );
if ( ! $page ) {
$page = 1;
}
$max_page = get_comment_pages_count();
$defaults = array(
'base' => add_query_arg( 'cpage', '%#%' ),
'format' => '',
'total' => $max_page,
'current' => $page,
'echo' => true,
'type' => 'plain',
'add_fragment' => '#comments',
);
if ( $wp_rewrite->using_permalinks() ) {
$defaults['base'] = user_trailingslashit( trailingslashit( get_permalink() ) . $wp_rewrite->comments_pagination_base . '-%#%', 'commentpaged' );
}
$args = wp_parse_args( $args, $defaults );
$page_links = paginate_links( $args );
if ( $args['echo'] && 'array' !== $args['type'] ) {
echo $page_links;
} else {
return $page_links;
}
}
Related
Uses
| Uses | Description |
|---|---|
| paginate_links() wp-includes/general-template.php | Retrieves paginated links for archive post pages. |
| is_singular() wp-includes/query.php | Determines whether the query is for an existing single post of any post type (post, attachment, page, custom post types). |
| get_query_var() wp-includes/query.php | Retrieves the value of a query variable in the WP_Query class. |
| user_trailingslashit() wp-includes/link-template.php | Retrieves a trailing-slashed string if the site is set for adding trailing slashes. |
| WP_Rewrite::using_permalinks() wp-includes/class-wp-rewrite.php | Determines whether permalinks are being used. |
| get_comment_pages_count() wp-includes/comment.php | Calculates the total number of comment pages. |
| trailingslashit() wp-includes/formatting.php | Appends a trailing slash. |
| wp_parse_args() wp-includes/functions.php | Merges user defined arguments into defaults array. |
| add_query_arg() wp-includes/functions.php | Retrieves a modified URL query string. |
| get_permalink() wp-includes/link-template.php | Retrieves the full permalink for the current post or post ID. |
Used By
| Used By | Description |
|---|---|
| get_the_comments_pagination() wp-includes/link-template.php | Retrieves a paginated navigation to next/previous set of comments, when applicable. |
Changelog
| Version | Description |
|---|---|
| 2.7.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/paginate_comments_links