WordPress.org

Make WordPress Core

Ticket #7635: separate_comments.diff

File separate_comments.diff, 1.9 KB (added by ryan, 10 years ago)

Add separate_comments flag to comments_template()

  • wp-includes/comment-template.php

     
    726726 * @uses $withcomments Will not try to get the comments if the post has none.
    727727 *
    728728 * @param string $file Optional, default '/comments.php'. The file to load
     729 * @param bool $separate_comments Optional, whether to separate the comments by comment type. Default is false.
    729730 * @return null Returns null if no comments appear
    730731 */
    731 function comments_template( $file = '/comments.php' ) {
     732function comments_template( $file = '/comments.php', $separate_comments = false ) {
    732733        global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_ID, $user_identity;
    733734
    734735        if ( ! (is_single() || is_page() || $withcomments) )
    735736                return;
    736737
     738        if ( empty($file) )
     739                $file = '/comments.php';
     740
    737741        $req = get_option('require_name_email');
    738742        $commenter = wp_get_current_commenter();
    739743        extract($commenter, EXTR_SKIP);
     
    747751                $comments = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND ( comment_approved = '1' OR ( comment_author = %s AND comment_author_email = %s AND comment_approved = '0' ) ) ORDER BY comment_date", $post->ID, $comment_author, $comment_author_email));
    748752        }
    749753
    750         // keep $comments for legacy's sake (remember $table*? ;) )
     754        // keep $comments for legacy's sake
    751755        $wp_query->comments = apply_filters( 'comments_array', $comments, $post->ID );
    752756        $comments = &$wp_query->comments;
    753757        $wp_query->comment_count = count($wp_query->comments);
    754758        update_comment_cache($wp_query->comments);
    755759
     760        if ( $separate_comments ) {
     761                $wp_query->comments_by_type = &separate_comments($comments);
     762                $comments_by_type = &$wp_query->comments_by_type;
     763        }
     764
    756765        define('COMMENTS_TEMPLATE', true);
    757766
    758767        $include = apply_filters('comments_template', STYLESHEETPATH . $file );