Add arg to comments_template() for requesting separating comments by type. see #7635

git-svn-id: https://develop.svn.wordpress.org/trunk@9092 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren 2008-10-06 23:16:26 +00:00
parent 1da36b352f
commit a7789a4124
1 changed files with 11 additions and 2 deletions

View File

@ -726,14 +726,18 @@ function wp_comment_form_unfiltered_html_nonce() {
* @uses $withcomments Will not try to get the comments if the post has none. * @uses $withcomments Will not try to get the comments if the post has none.
* *
* @param string $file Optional, default '/comments.php'. The file to load * @param string $file Optional, default '/comments.php'. The file to load
* @param bool $separate_comments Optional, whether to separate the comments by comment type. Default is false.
* @return null Returns null if no comments appear * @return null Returns null if no comments appear
*/ */
function comments_template( $file = '/comments.php' ) { function comments_template( $file = '/comments.php', $separate_comments = false ) {
global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_ID, $user_identity; global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_ID, $user_identity;
if ( ! (is_single() || is_page() || $withcomments) ) if ( ! (is_single() || is_page() || $withcomments) )
return; return;
if ( empty($file) )
$file = '/comments.php';
$req = get_option('require_name_email'); $req = get_option('require_name_email');
$commenter = wp_get_current_commenter(); $commenter = wp_get_current_commenter();
extract($commenter, EXTR_SKIP); extract($commenter, EXTR_SKIP);
@ -747,12 +751,17 @@ function comments_template( $file = '/comments.php' ) {
$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)); $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));
} }
// keep $comments for legacy's sake (remember $table*? ;) ) // keep $comments for legacy's sake
$wp_query->comments = apply_filters( 'comments_array', $comments, $post->ID ); $wp_query->comments = apply_filters( 'comments_array', $comments, $post->ID );
$comments = &$wp_query->comments; $comments = &$wp_query->comments;
$wp_query->comment_count = count($wp_query->comments); $wp_query->comment_count = count($wp_query->comments);
update_comment_cache($wp_query->comments); update_comment_cache($wp_query->comments);
if ( $separate_comments ) {
$wp_query->comments_by_type = &separate_comments($comments);
$comments_by_type = &$wp_query->comments_by_type;
}
define('COMMENTS_TEMPLATE', true); define('COMMENTS_TEMPLATE', true);
$include = apply_filters('comments_template', STYLESHEETPATH . $file ); $include = apply_filters('comments_template', STYLESHEETPATH . $file );