Codex

Template Tags/wp list comments

Contents

Description

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

Usage

 <?php wp_list_comments$args ); ?> 

Default Usage

<?php $args = 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'  => 
 ); ?>

max_depth, per_page, and reverse_top_level can be more easily controlled through the Administration Panel Settings_Discussion_SubPanel but a theme can override those settings here.

Parameters

This needs expanding / explaining.

avatar_size 
(int) Size that the avatar should be shown as, in pixels. Default: 32. http://gravatar.com/ supports sizes between 1 and 512.
style 
(string) Can be either 'div', 'ol', or 'ul', to display comments using divs, ordered, or unordered lists. Defaults to 'ul'. Note that there are containing tags that must be written explicitly such as
<div class="commentlist"><?php wp_list_comments(array('style' => 'div')); ?></div>
or
<ol class="commentlist"><?php wp_list_comments(array('style' => 'ol')); ?></ol>
type 
(string) The type of comment(s) to display. Can be 'all', 'comment', 'trackback', 'pingback', or 'pings'. 'pings' is 'trackback' and 'pingback' together. Default is 'all'.
reply_text 
(string) Text to display in each comment as a reply link. (This isn't an argument of this function but it gets passed to the get_comment_reply_link function.) Default is 'Reply'.
login_text 
(string) Text to display in each comment if users must be registered and logged in to comment . (This isn't an argument of this function but it gets passed to the get_comment_reply_link function.) Default is 'Log in to Reply'.
callback 
(string) The name of a custom function to use to display each comment. Defaults to null. Using this will make your custom function get called to display each comment, bypassing all internal WordPress functionality in this respect. Use to customize comments display for extreme changes to the HTML layout. Not recommended.

Examples

Default Usage

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>

Comments Only With A Custom Comment Display

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 an 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) {
   $GLOBALS['comment'] = $comment; ?>
   <li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
     <div id="comment-<?php comment_ID(); ?>">
      <div class="comment-author vcard">
         <?php echo get_avatar($comment,$size='48',$default='<path_to_url>' ); ?>

         <?php printf(__('<cite class="fn">%s</cite> <span class="says">says:</span>'), get_comment_author_link()) ?>
      </div>
      <?php if ($comment->comment_approved == '0') : ?>
         <em><?php _e('Your comment is awaiting moderation.') ?></em>
         <br />
      <?php endif; ?>

      <div class="comment-meta commentmetadata"><a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ?>"><?php 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('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
      </div>
     </div>
<?php
        }

Note the lack of a trailing </li>. WordPress will add it itself once it's done listing any children and whatnot.

Change Log

Since: 2.7.0

Source File

wp_list_comments() is located in wp-includes/comment-template.php.

Related

comments_number, comments_link, comments_rss_link, comments_popup_script, comments_popup_link, comment_ID, comment_author, comment_author_IP, comment_author_email, comment_author_url, comment_author_email_link, comment_author_url_link, comment_author_link, comment_type, comment_text, comment_excerpt, comment_date, comment_time, comment_author_rss, comment_text_rss, comment_link_rss, permalink_comments_rss, wp_list_comments, comment_reply_link, cancel_comment_reply_link, comment_form_title, comment_id_fields, previous_comments_link, next_comments_link, paginate_comments_links

wp_list_authors, wp_list_categories, wp_list_pages, wp_list_bookmarks, wp_list_comments, wp_get_archives, wp_page_menu, wp_dropdown_pages, wp_dropdown_categories, wp_dropdown_users

See also index of Function Reference and index of Template Tags.