Displays or retrieves pagination links for the comments on the current post.
$argsstring|arrayoptional
base stringformat stringtotal intmax_num_pages or 1.current int'paged' query var or 1.aria_current string'page', 'step', 'location', 'date', 'time', 'true', 'false'. Default is 'page'.show_all boolend_size intmid_size intprev_next boolprev_text stringnext_text stringtype string'plain', 'array' and 'list'. Default is 'plain'.add_args arrayadd_fragment stringbefore_page_number stringafter_page_number stringDefault:array()
'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.'type' argument.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.
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;
}
}
| Version | Description |
|---|---|
| 2.7.0 | Introduced. |
© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/paginate_comments_links