Languages: English • 日本語 한국어 • (Add your language)
Displays all comments for a post or Page based on a variety of parameters including ones set in the administration area.
See also: Migrating Plugins and Themes to 2.7
<?php wp_list_comments( $args, $comments ); ?>
<?php $args = array( 'walker' => null, 'max_depth' => '', 'style' => 'ul', 'callback' => null, 'end-callback' => null, 'type' => 'all', 'reply_text' => 'Reply', 'page' => '', 'per_page' => '', 'avatar_size' => 32, 'reverse_top_level' => null, 'reverse_children' => '', 'format' => 'html5', // or 'xhtml' if no 'HTML5' theme support 'short_ping' => false, // @since 3.6 'echo' => true // boolean, default is true ); ?>
The 'max_depth', 'per_page' and 'reverse_top_level' parameters can be more easily controlled through the Discussion Settings Administration Panel but a theme can override those settings.
<?php wp_list_comments( array( 'walker' => new Walker_Comment() ) );
<div class="comment list"> <?php wp_list_comments( array( 'style' => 'div' ) ); ?> </div>
OR
<ol class="comment list"> <?php wp_list_comments( array( 'style' => 'ol' ) ); ?> </ol>
<div>
, <ol>
, or <ul>
tag (corresponding with the style parameter), but not the closing tags. WordPress will supply the closing tag automatically, or you can use end-callback to override this default. The callback is separate from the end-callback to facilitate hierarchical comments. Use with caution.</div>
, </ol>
, or </li>
based on the style parameter. Use to customize the ending tags for a comment. The callback is separate from the end-callback to facilitate hierarchical comments. Use with caution.'all'
, 'comment'
, 'trackback'
, 'pingback'
, or 'pings'
. 'pings'
is both 'trackback'
and 'pingback'
together.get_comment_reply_link
function.)true
will display the most recent comment first then going back in order, and setting this to false
will show the oldest comments first. If not specified, it will use the value stored in the WordPress dashboard settings.true
will display the children (reply level comments) with the most recent ones first, then going back in order.current_theme_supports( 'html5' )
setting.Outputs an ordered list of the comments. Things like threading or paging being enabled or disabled are controlled via the Settings Discussion SubPanel.
<ol class="commentlist"> <?php wp_list_comments(); ?> </ol>
Displays just comments (no pingbacks or trackbacks) while using a custom callback function to control the look of the comment. You may want to add a max_depth=X parameter, if the reply links are not appearing.
<ul class="commentlist"> <?php wp_list_comments( 'type=comment&callback=mytheme_comment' ); ?> </ul>
You will need to define your custom callback function in your theme's functions.php file. Here is an example:
function mytheme_comment($comment, $args, $depth) { if ( 'div' === $args['style'] ) { $tag = 'div'; $add_below = 'comment'; } else { $tag = 'li'; $add_below = 'div-comment'; }?> <<?php echo $tag; ?> <?php comment_class( empty( $args['has_children'] ) ? '' : 'parent' ); ?> id="comment-<?php comment_ID() ?>"><?php if ( 'div' != $args['style'] ) { ?> <div id="div-comment-<?php comment_ID() ?>" class="comment-body"><?php } ?> <div class="comment-author vcard"><?php if ( $args['avatar_size'] != 0 ) { echo get_avatar( $comment, $args['avatar_size'] ); } printf( __( '<cite class="fn">%s</cite> <span class="says">says:</span>' ), get_comment_author_link() ); ?> </div><?php if ( $comment->comment_approved == '0' ) { ?> <em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.' ); ?></em><br/><?php } ?> <div class="comment-meta commentmetadata"> <a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ); ?>"><?php /* translators: 1: date, 2: time */ printf( __('%1$s at %2$s'), get_comment_date(), get_comment_time() ); ?> </a><?php edit_comment_link( __( '(Edit)' ), ' ', '' ); ?> </div> <?php comment_text(); ?> <div class="reply"><?php comment_reply_link( array_merge( $args, array( 'add_below' => $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?> </div><?php if ( 'div' != $args['style'] ) : ?> </div><?php endif; }
Note the lack of a trailing </li>
. In order to accommodate nested replies, WordPress will add the appropriate closing tag after listing any child elements.
Outputs an ordered list of comments for a specific page or post. Things like threading or paging being enabled or disabled are controlled via the Settings Discussion SubPanel.
<ol class="commentlist"> <?php //Gather comments for a specific page/post $comments = get_comments(array( 'post_id' => XXX, 'status' => 'approve' //Change this to the type of comments to be displayed )); //Display the list of comments wp_list_comments(array( 'per_page' => 10, //Allow comment pagination 'reverse_top_level' => false //Show the oldest comments at the top of the list ), $comments); ?> </ol>
Since: 2.7.0
wp_list_comments() is located in wp-includes/comment-template.php
.