From 83dce74554822d851586f84065d9edae54af5a5c Mon Sep 17 00:00:00 2001 From: ryan Date: Thu, 13 Nov 2008 20:36:36 +0000 Subject: [PATCH] wp_list_comments() fixes when passing type. Props Viper007Bond. fixes #8168 git-svn-id: http://svn.automattic.com/wordpress/trunk@9667 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/comment-template.php | 71 +++++++++++++++----------------- 1 file changed, 34 insertions(+), 37 deletions(-) diff --git a/wp-includes/comment-template.php b/wp-includes/comment-template.php index dd74060129..ea19a31043 100644 --- a/wp-includes/comment-template.php +++ b/wp-includes/comment-template.php @@ -1213,6 +1213,33 @@ function wp_list_comments($args = array(), $comments = null ) { $r = wp_parse_args( $args, $defaults ); + // Figure out what comments we'll be looping through ($_comments) + if ( null !== $comments ) { + $comments = (array) $comments; + if ( empty($comments) ) + return; + if ( 'all' != $r['type'] ) { + $comments_by_type = &separate_comments($comments); + if ( empty($comments_by_type[$r['type']]) ) + return; + $_comments = $comments_by_type[$r['type']]; + } else { + $_comments = $comments; + } + } else { + if ( empty($wp_query->comments) ) + return; + if ( 'all' != $r['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[$r['type']]) ) + return; + $_comments = $wp_query->comments_by_type[$r['type']]; + } else { + $_comments = $wp_query->comments; + } + } + if ( '' === $r['per_page'] && get_option('page_comments') ) $r['per_page'] = get_query_var('comments_per_page'); @@ -1229,16 +1256,12 @@ function wp_list_comments($args = array(), $comments = null ) { } if ( '' === $r['page'] ) { - if ( empty($comments) ) { + if ( empty($overridden_cpage) ) { $r['page'] = get_query_var('cpage'); } else { - if ( empty($overridden_cpage) ) { - $r['page'] = get_query_var('cpage'); - } else { - $threaded = ( -1 == $r['max_depth'] ) ? false : true; - $r['page'] = ( 'newest' == get_option('default_comments_page') ) ? get_comment_pages_count($comments, $r['per_page'], $threaded) : 1; - set_query_var( 'cpage', $r['page'] ); - } + $threaded = ( -1 == $r['max_depth'] ) ? false : true; + $r['page'] = ( 'newest' == get_option('default_comments_page') ) ? get_comment_pages_count($_comments, $r['per_page'], $threaded) : 1; + set_query_var( 'cpage', $r['page'] ); } } // Validation check @@ -1252,36 +1275,10 @@ function wp_list_comments($args = array(), $comments = null ) { extract( $r, EXTR_SKIP ); if ( empty($walker) ) - $walker = new Walker_Comment; + $walker = new Walker_Comment; - 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; - $walker->paged_walk($wp_query->comments_by_type[$type], $max_depth, $page, $per_page, $r); - $wp_query->max_num_comment_pages = $walker->max_pages; - return; - } - $walker->paged_walk($wp_query->comments, $max_depth, $page, $per_page, $r); - $wp_query->max_num_comment_pages = $walker->max_pages; - } else { - if ( empty($comments) ) - return; - if ( 'all' != $type ) { - $comments_by_type = &separate_comments($comments); - if ( empty($comments_by_type[$type]) ) - return; - $walker->paged_walk($comments_by_type[$type], $max_depth, $page, $per_page, $r); - $wp_query->max_num_comment_pages = $walker->max_pages; - return; - } - $walker->paged_walk($comments, $max_depth, $page, $per_page, $r); - $wp_query->max_num_comment_pages = $walker->max_pages; - } + $walker->paged_walk($_comments, $max_depth, $page, $per_page, $r); + $wp_query->max_num_comment_pages = $walker->max_pages; } ?> \ No newline at end of file