wp_list_comments() – Displays a list of comments.

You appear to be a bot. Output may be restricted

Description

Displays a list of comments.

Used in the comments.php template to list comments for a particular post.

Usage

$void|string = wp_list_comments( $args, $comments );

Parameters

$args
( string|array ) optional – { Optional. Formatting options.
$walker
( object ) optional – Instance of a Walker class to list comments. Default null.
$max_depth
( int ) optional – The maximum comments depth. Default empty.
$style
( string ) optional – The style of list ordering. Accepts 'ul', 'ol', or 'div'. 'div' will result in no additional list markup. Default 'ul'.
$callback
( callable ) optional – Callback function to use. Default null.
$end-callback
( callable ) optional – Callback function to use at the end. Default null.
$type
( string ) optional – Type of comments to list. Accepts 'all', 'comment', 'pingback', 'trackback', 'pings'. Default 'all'.
$page
( int ) optional – Page ID to list comments for. Default empty.
$per_page
( int ) optional – Number of comments to list per page. Default empty.
$avatar_size
( int ) optional – Height and width dimensions of the avatar size. Default 32.
$reverse_top_level
( bool ) optional – Ordering of the listed comments. If true, will display newest comments first. Default null.
$reverse_children
( bool ) optional – Whether to reverse child comments in the list. Default null.
$format
( string ) optional – How to format the comments list. Accepts 'html5', 'xhtml'. Default 'html5' if the theme supports it.
$short_ping
( bool ) optional – Whether to output short pings. Default false.
$echo
( bool ) optional – Whether to echo the output or return it. Default true. }
$comments
( WP_Comment[] ) optional – Optional. Array of WP_Comment objects.

Returns

void|string Void if 'echo' argument is true, or no comments to list. Otherwise, HTML list of comments.

Source

File name: wordpress/wp-includes/comment-template.php
Lines:

1 to 100 of 191
function wp_list_comments( $args = array(), $comments = null ) {
  global $wp_query, $comment_alt, $comment_depth, $comment_thread_alt, $overridden_cpage, $in_comment_loop;

  $in_comment_loop = true;

  $comment_alt        = 0;
  $comment_thread_alt = 0;
  $comment_depth      = 1;

  $defaults = array(
    'walker'            => null,
    'max_depth'         => '',
    'style'             => 'ul',
    'callback'          => null,
    'end-callback'      => null,
    'type'              => 'all',
    'page'              => '',
    'per_page'          => '',
    'avatar_size'       => 32,
    'reverse_top_level' => null,
    'reverse_children'  => '',
    'format'            => current_theme_supports( 'html5', 'comment-list' ) ? 'html5' : 'xhtml',
    'short_ping'        => false,
    'echo'              => true,
  );

  $parsed_args = wp_parse_args( $args, $defaults );

  
/**
 * Filters the arguments used in retrieving the comment list.
 *
 * @since 4.0.0
 *
 * @see wp_list_comments()
 *
 * @param array $parsed_args An array of arguments for displaying comments.
 */
  $parsed_args = apply_filters( 'wp_list_comments_args', $parsed_args );

  // Figure out what comments we'll be looping through ($_comments).
  if ( null !== $comments ) {
    $comments = (array) $comments;
    if ( empty( $comments ) ) {
      return;
    }
    if ( 'all' !== $parsed_args['type'] ) {
      $comments_by_type = separate_comments( $comments );
      if ( empty( $comments_by_type[ $parsed_args['type'] ] ) ) {
        return;
      }
      $_comments = $comments_by_type[ $parsed_args['type'] ];
    } else {
      $_comments = $comments;
    }
  } else {
    /*
		 * If 'page' or 'per_page' has been passed, and does not match what's in $wp_query,
		 * perform a separate comment query and allow Walker_Comment to paginate.
		 */
    if ( $parsed_args['page'] || $parsed_args['per_page'] ) {
      $current_cpage = get_query_var( 'cpage' );
      if ( ! $current_cpage ) {
        $current_cpage = 'newest' === get_option( 'default_comments_page' ) ? 1 : $wp_query->max_num_comment_pages;
      }

      $current_per_page = get_query_var( 'comments_per_page' );
      if ( $parsed_args['page'] != $current_cpage || $parsed_args['per_page'] != $current_per_page ) {
        $comment_args = array(
          'post_id' => get_the_ID(),
          'orderby' => 'comment_date_gmt',
          'order'   => 'ASC',
          'status'  => 'approve',
        );

        if ( is_user_logged_in() ) {
          $comment_args['include_unapproved'] = array( get_current_user_id() );
        } else {
          $unapproved_email = wp_get_unapproved_comment_author_email();

          if ( $unapproved_email ) {
            $comment_args['include_unapproved'] = array( $unapproved_email );
          }
        }

        $comments = get_comments( $comment_args );

        if ( 'all' !== $parsed_args['type'] ) {
          $comments_by_type = separate_comments( $comments );
          if ( empty( $comments_by_type[ $parsed_args['type'] ] ) ) {
            return;
          }

          $_comments = $comments_by_type[ $parsed_args['type'] ];
        } else {
          $_comments = $comments;
        }
      }

      // Otherwise, fall back on the comments from `$wp_query->comments`.
    } else {
 

 View on GitHub View on Trac