WordPress.org

Make WordPress Core

Changeset 8897


Ignore:
Timestamp:
09/16/08 00:23:38 (6 years ago)
Author:
ryan
Message:

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

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-content/themes/default/comments.php

    r8869 r8897  
    1616 
    1717    <ol class="commentlist"> 
    18     <?php wp_list_comments($comments); ?> 
     18    <?php wp_list_comments('type=pings'); ?> 
    1919    </ol> 
    2020 
  • trunk/wp-includes/comment-template.php

    r8878 r8897  
    731731 
    732732    // keep $comments for legacy's sake (remember $table*? ;) ) 
    733     $comments = $wp_query->comments = apply_filters( 'comments_array', $comments, $post->ID ); 
     733    $wp_query->comments = apply_filters( 'comments_array', $comments, $post->ID ); 
     734    $comments = &$wp_query->comments; 
    734735    $wp_query->comment_count = count($wp_query->comments); 
    735     update_comment_cache($comments); 
     736    update_comment_cache($wp_query->comments); 
    736737 
    737738    define('COMMENTS_TEMPLATE', true); 
     
    971972 * @uses Walker_Comment 
    972973 * 
    973  * @param $comments array Array of comment object to list 
    974  * @param $args string|array Additional arguments 
    975  */ 
    976 function wp_list_comments(&$comments, $args = array() ) { 
    977     $defaults = array('walker' => null, 'depth' => 3, 'style' => 'ul', 'callback' => null, 'end-callback' => null); 
     974 * @param $args string|array Formatting options 
     975    * @param $comments array Optional array of comment objects.  Defaults to $wp_query->comments 
     976 */ 
     977function wp_list_comments($args = array(), $comments = null ) { 
     978    global $wp_query; 
     979 
     980    $defaults = array('walker' => null, 'depth' => 3, 'style' => 'ul', 'callback' => null, 'end-callback' => null, 'type' => 'all'); 
    978981 
    979982    $r = wp_parse_args( $args, $defaults ); 
     
    982985 
    983986    if ( empty($walker) ) 
    984         $walker = new Walker_Comment; 
    985  
    986     $walker->walk($comments, $depth, $r); 
     987    $walker = new Walker_Comment; 
     988 
     989    if ( empty($comments) ) { 
     990        if ( empty($wp_query->comments) ) 
     991            return; 
     992        if ( 'all' != $type ) { 
     993            if ( empty($wp_query->comments_by_type) ) 
     994                $wp_query->comments_by_type = &separate_comments($wp_query->comments); 
     995            if ( empty($wp_query->comments_by_type[$type]) ) 
     996                return; 
     997            return $walker->walk($wp_query->comments_by_type[$type], $depth, $r); 
     998        } 
     999        $walker->walk($wp_query->comments, $depth, $r); 
     1000    } else { 
     1001        if ( empty($comments) ) 
     1002            return; 
     1003        if ( 'all' != $type ) { 
     1004            $comments_by_type = separate_comments($comments); 
     1005            if ( empty($comments_by_type[$type]) ) 
     1006                return; 
     1007            return $walker->walk($comments_by_type[$type], $depth, $r); 
     1008        } 
     1009        $walker->walk($comments, $depth, $r); 
     1010    } 
    9871011} 
    9881012 
  • trunk/wp-includes/comment.php

    r8892 r8897  
    455455        } 
    456456    } 
     457} 
     458 
     459/** 
     460 * Separates an array of comments into an array keyed by comment_type. 
     461 * 
     462 * @since 2.7 
     463 * 
     464 * @param array $comments Array of comments 
     465 * @return array Array of comments keyed by comment_type. 
     466 */ 
     467function &separate_comments(&$comments) { 
     468    $comments_by_type = array('comment' => array(), 'trackback' => array(), 'pingback' => array(), 'pings' => array()); 
     469    $count = count($comments); 
     470    for ( $i = 0; $i < $count; $i++ ) { 
     471        $type = $comments[$i]->comment_type; 
     472        $comments_by_type[$type][] = &$comments[$i]; 
     473        if ( 'trackback' == $type || 'pingback' == $type ) 
     474            $comments_by_type['pings'][] = &$comments[$i]; 
     475    } 
     476 
     477    return $comments_by_type; 
    457478} 
    458479 
Note: See TracChangeset for help on using the changeset viewer.