get_comments_pagenum_link() WordPress Function

The get_comments_pagenum_link() function is used to retrieve the correct page number link for the comments list pagination. This function is used by the WordPress comment system to provide links to the previous and next pages of comments.

get_comments_pagenum_link( int $pagenum = 1, int $max_page ) #

Retrieves the comments page number link.


Parameters

$pagenum

(int)(Optional) Page number.

Default value: 1

$max_page

(int)(Optional) The maximum number of comment pages. Default 0.


Top ↑

Return

(string) The comments page number link URL.


Top ↑

Source

File: wp-includes/link-template.php

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 );
}


Top ↑

Changelog

Changelog
VersionDescription
2.7.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More