On this page
get_the_comments_navigation( array $args = array() ): string
Retrieves navigation to next/previous set of comments, when applicable.
Parameters
$argsarray Optional-
Default comments navigation arguments.
prev_textstringAnchor text to display in the previous comments link.
Default 'Older comments'.next_textstringAnchor text to display in the next comments link.
Default 'Newer comments'.screen_reader_textstringScreen reader text for the nav element. Default 'Comments navigation'.aria_labelstringARIA label text for the nav element. Default'Comments'.classstringCustom class for the nav element. Default'comment-navigation'.
Default:
array()
Return
string Markup for comments links.
Source
File: wp-includes/link-template.php. View all references
function get_the_comments_navigation( $args = array() ) {
$navigation = '';
// Are there comments to navigate through?
if ( get_comment_pages_count() > 1 ) {
// Make sure the nav element has an aria-label attribute: fallback to the screen reader text.
if ( ! empty( $args['screen_reader_text'] ) && empty( $args['aria_label'] ) ) {
$args['aria_label'] = $args['screen_reader_text'];
}
$args = wp_parse_args(
$args,
array(
'prev_text' => __( 'Older comments' ),
'next_text' => __( 'Newer comments' ),
'screen_reader_text' => __( 'Comments navigation' ),
'aria_label' => __( 'Comments' ),
'class' => 'comment-navigation',
)
);
$prev_link = get_previous_comments_link( $args['prev_text'] );
$next_link = get_next_comments_link( $args['next_text'] );
if ( $prev_link ) {
$navigation .= '<div class="nav-previous">' . $prev_link . '</div>';
}
if ( $next_link ) {
$navigation .= '<div class="nav-next">' . $next_link . '</div>';
}
$navigation = _navigation_markup( $navigation, $args['class'], $args['screen_reader_text'], $args['aria_label'] );
}
return $navigation;
}
Related
Uses
| Uses | Description |
|---|---|
| _navigation_markup() wp-includes/link-template.php | Wraps passed links in navigational markup. |
| get_previous_comments_link() wp-includes/link-template.php | Retrieves the link to the previous comments page. |
| get_next_comments_link() wp-includes/link-template.php | Retrieves the link to the next comments page. |
| get_comment_pages_count() wp-includes/comment.php | Calculates the total number of comment pages. |
| __() wp-includes/l10n.php | Retrieves the translation of $text. |
| wp_parse_args() wp-includes/functions.php | Merges user defined arguments into defaults array. |
Used By
| Used By | Description |
|---|---|
| the_comments_navigation() wp-includes/link-template.php | Displays navigation to next/previous set of comments, when applicable. |
Changelog
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/get_the_comments_navigation