On this page
get_comments_pagenum_link( int $pagenum = 1, int $max_page ): string
Retrieves the comments page number link.
Parameters
$pagenumint Optional-
Page number.
Default:
1 $max_pageint Optional-
The maximum number of comment pages. Default 0.
Return
string The comments page number link URL.
Source
File: wp-includes/link-template.php. View all references
function get_comments_pagenum_link( $pagenum = 1, $max_page = 0 ) {
global $wp_rewrite;
$pagenum = (int) $pagenum;
$result = get_permalink();
if ( 'newest' === get_option( 'default_comments_page' ) ) {
if ( $pagenum != $max_page ) {
if ( $wp_rewrite->using_permalinks() ) {
$result = user_trailingslashit( trailingslashit( $result ) . $wp_rewrite->comments_pagination_base . '-' . $pagenum, 'commentpaged' );
} else {
$result = add_query_arg( 'cpage', $pagenum, $result );
}
}
} elseif ( $pagenum > 1 ) {
if ( $wp_rewrite->using_permalinks() ) {
$result = user_trailingslashit( trailingslashit( $result ) . $wp_rewrite->comments_pagination_base . '-' . $pagenum, 'commentpaged' );
} else {
$result = add_query_arg( 'cpage', $pagenum, $result );
}
}
$result .= '#comments';
/**
* Filters the comments page number link for the current request.
*
* @since 2.7.0
*
* @param string $result The comments page number link.
*/
return apply_filters( 'get_comments_pagenum_link', $result );
}
Hooks
- apply_filters( 'get_comments_pagenum_link',
string $result ) -
Filters the comments page number link for the current request.
Related
Uses
| Uses | Description |
|---|---|
| WP_Rewrite::using_permalinks() wp-includes/class-wp-rewrite.php | Determines whether permalinks are being used. |
| user_trailingslashit() wp-includes/link-template.php | Retrieves a trailing-slashed string if the site is set for adding trailing slashes. |
| trailingslashit() wp-includes/formatting.php | Appends a trailing slash. |
| 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. |
| apply_filters() wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. |
| get_option() wp-includes/option.php | Retrieves an option value based on an option name. |
Used By
| Used By | Description |
|---|---|
| wp_get_canonical_url() wp-includes/link-template.php | Returns the canonical URL for a post. |
| get_next_comments_link() wp-includes/link-template.php | Retrieves the link to the next comments page. |
| get_previous_comments_link() wp-includes/link-template.php | Retrieves the link to the previous comments page. |
Changelog
| Version | Description |
|---|---|
| 2.7.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/get_comments_pagenum_link