diff --git a/wp-content/themes/default/comments.php b/wp-content/themes/default/comments.php
index 6820449c44..2f5fd4d864 100644
--- a/wp-content/themes/default/comments.php
+++ b/wp-content/themes/default/comments.php
@@ -15,7 +15,7 @@
diff --git a/wp-includes/comment-template.php b/wp-includes/comment-template.php
index b10b8ce06a..a11a5e3406 100644
--- a/wp-includes/comment-template.php
+++ b/wp-includes/comment-template.php
@@ -730,9 +730,10 @@ function comments_template( $file = '/comments.php' ) {
}
// keep $comments for legacy's sake (remember $table*? ;) )
- $comments = $wp_query->comments = apply_filters( 'comments_array', $comments, $post->ID );
+ $wp_query->comments = apply_filters( 'comments_array', $comments, $post->ID );
+ $comments = &$wp_query->comments;
$wp_query->comment_count = count($wp_query->comments);
- update_comment_cache($comments);
+ update_comment_cache($wp_query->comments);
define('COMMENTS_TEMPLATE', true);
@@ -970,20 +971,43 @@ class Walker_Comment extends Walker {
* @since 2.7
* @uses Walker_Comment
*
- * @param $comments array Array of comment object to list
- * @param $args string|array Additional arguments
+ * @param $args string|array Formatting options
+ * @param $comments array Optional array of comment objects. Defaults to $wp_query->comments
*/
-function wp_list_comments(&$comments, $args = array() ) {
- $defaults = array('walker' => null, 'depth' => 3, 'style' => 'ul', 'callback' => null, 'end-callback' => null);
+function wp_list_comments($args = array(), $comments = null ) {
+ global $wp_query;
+
+ $defaults = array('walker' => null, 'depth' => 3, 'style' => 'ul', 'callback' => null, 'end-callback' => null, 'type' => 'all');
$r = wp_parse_args( $args, $defaults );
extract( $r, EXTR_SKIP );
if ( empty($walker) )
- $walker = new Walker_Comment;
+ $walker = new Walker_Comment;
- $walker->walk($comments, $depth, $r);
+ if ( empty($comments) ) {
+ if ( empty($wp_query->comments) )
+ return;
+ if ( 'all' != $type ) {
+ if ( empty($wp_query->comments_by_type) )
+ $wp_query->comments_by_type = &separate_comments($wp_query->comments);
+ if ( empty($wp_query->comments_by_type[$type]) )
+ return;
+ return $walker->walk($wp_query->comments_by_type[$type], $depth, $r);
+ }
+ $walker->walk($wp_query->comments, $depth, $r);
+ } else {
+ if ( empty($comments) )
+ return;
+ if ( 'all' != $type ) {
+ $comments_by_type = separate_comments($comments);
+ if ( empty($comments_by_type[$type]) )
+ return;
+ return $walker->walk($comments_by_type[$type], $depth, $r);
+ }
+ $walker->walk($comments, $depth, $r);
+ }
}
?>
\ No newline at end of file
diff --git a/wp-includes/comment.php b/wp-includes/comment.php
index 394e9f31d8..677f262c7c 100644
--- a/wp-includes/comment.php
+++ b/wp-includes/comment.php
@@ -456,6 +456,27 @@ function check_comment_flood_db( $ip, $email, $date ) {
}
}
+/**
+ * Separates an array of comments into an array keyed by comment_type.
+ *
+ * @since 2.7
+ *
+ * @param array $comments Array of comments
+ * @return array Array of comments keyed by comment_type.
+ */
+function &separate_comments(&$comments) {
+ $comments_by_type = array('comment' => array(), 'trackback' => array(), 'pingback' => array(), 'pings' => array());
+ $count = count($comments);
+ for ( $i = 0; $i < $count; $i++ ) {
+ $type = $comments[$i]->comment_type;
+ $comments_by_type[$type][] = &$comments[$i];
+ if ( 'trackback' == $type || 'pingback' == $type )
+ $comments_by_type['pings'][] = &$comments[$i];
+ }
+
+ return $comments_by_type;
+}
+
/**
* Does comment contain blacklisted characters or words.
*