Add type argument to wp_list_comments(). Make comments arg optional. Introduce separate_comments(). see #7635

git-svn-id: http://svn.automattic.com/wordpress/trunk@8897 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2008-09-16 00:23:38 +00:00
parent 1d9facfbe7
commit 3aad45d7e4
3 changed files with 54 additions and 9 deletions

View File

@ -15,7 +15,7 @@
<h3 id="comments"><?php comments_number('No Responses', 'One Response', '% Responses' );?> to &#8220;<?php the_title(); ?>&#8221;</h3>
<ol class="commentlist">
<?php wp_list_comments($comments); ?>
<?php wp_list_comments('type=pings'); ?>
</ol>
<?php else : // this is displayed if there are no comments so far ?>

View File

@ -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);
}
}
?>

View File

@ -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.
*