get_the_comments_navigation

Retrieves navigation to next/previous set of comments, when applicable.

Description

(string) get_the_comments_navigation( (array) $args = array() ); 

Returns (string)

Markup for comments links.

Parameters (1)

0. $args — Optional. (array) => array()
Default comments navigation arguments.

Options

  • prev_text (string) => 'Older comments'

    Anchor text to display in the previous comments link.

  • next_text (string) => 'Newer comments'

    Anchor text to display in the next comments link.

array(

    /**
     * Anchor text to display in the previous comments link.
     *
     * @type string
     * @default 'Older comments'
     */
    'prev_text' => 'Older comments',

    /**
     * Anchor text to display in the next comments link.
     *
     * @type string
     * @default 'Newer comments'
     */
    'next_text' => 'Newer comments'
);        


Usage

  1. if ( !function_exists( 'get_the_comments_navigation' ) ) { 
  2. require_once ABSPATH . WPINC . '/link-template.php'; 
  3.  
  4. // Optional. Default comments navigation arguments. 
  5. $args = array( 
  6. 'prev_text' => 'Older comments', 
  7. 'next_text' => 'Newer comments' 
  8. ); 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = get_the_comments_navigation($args); 
  12.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/link-template.php  
  1. function get_the_comments_navigation( $args = array() ) { 
  2. $navigation = ''; 
  3.  
  4. // Are there comments to navigate through? 
  5. if ( get_comment_pages_count() > 1 ) { 
  6. $args = wp_parse_args( $args, array( 
  7. 'prev_text' => __( 'Older comments' ),  
  8. 'next_text' => __( 'Newer comments' ),  
  9. 'screen_reader_text' => __( 'Comments navigation' ),  
  10. ) ); 
  11.  
  12. $prev_link = get_previous_comments_link( $args['prev_text'] ); 
  13. $next_link = get_next_comments_link( $args['next_text'] ); 
  14.  
  15. if ( $prev_link ) { 
  16. $navigation .= '<div class="nav-previous">' . $prev_link . '</div>'; 
  17.  
  18. if ( $next_link ) { 
  19. $navigation .= '<div class="nav-next">' . $next_link . '</div>'; 
  20.  
  21. $navigation = _navigation_markup( $navigation, 'comment-navigation', $args['screen_reader_text'] ); 
  22.  
  23. return $navigation;