On this page
get_next_comments_link( string $label = '', int $max_page ): string|void
Retrieves the link to the next comments page.
Parameters
$labelstring Optional-
Label for link text.
Default:
'' $max_pageint Optional-
Max page. Default 0.
Return
string|void HTML-formatted link for the next page of comments.
Source
File: wp-includes/link-template.php. View all references
function get_next_comments_link( $label = '', $max_page = 0 ) {
global $wp_query;
if ( ! is_singular() ) {
return;
}
$page = get_query_var( 'cpage' );
if ( ! $page ) {
$page = 1;
}
$nextpage = (int) $page + 1;
if ( empty( $max_page ) ) {
$max_page = $wp_query->max_num_comment_pages;
}
if ( empty( $max_page ) ) {
$max_page = get_comment_pages_count();
}
if ( $nextpage > $max_page ) {
return;
}
if ( empty( $label ) ) {
$label = __( 'Newer Comments »' );
}
/**
* Filters the anchor tag attributes for the next comments page link.
*
* @since 2.7.0
*
* @param string $attributes Attributes for the anchor tag.
*/
return '<a href="' . esc_url( get_comments_pagenum_link( $nextpage, $max_page ) ) . '" ' . apply_filters( 'next_comments_link_attributes', '' ) . '>' . preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&$1', $label ) . '</a>';
}
Hooks
- apply_filters( 'next_comments_link_attributes',
string $attributes ) -
Filters the anchor tag attributes for the next comments page link.
Related
Uses
| Uses | Description |
|---|---|
| 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. |
| get_comments_pagenum_link() wp-includes/link-template.php | Retrieves the comments page number link. |
| get_comment_pages_count() wp-includes/comment.php | Calculates the total number of comment pages. |
| __() wp-includes/l10n.php | Retrieves the translation of $text. |
| esc_url() wp-includes/formatting.php | Checks and cleans a URL. |
| apply_filters() wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. |
Used By
| Used By | Description |
|---|---|
| get_the_comments_navigation() wp-includes/link-template.php | Retrieves navigation to next/previous set of comments, when applicable. |
| next_comments_link() wp-includes/link-template.php | Displays the link to the next comments page. |
Changelog
| Version | Description |
|---|---|
| 2.7.1 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/get_next_comments_link