From 37fad7545b3a35699031a141ed7c9665445c8de4 Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Wed, 24 Sep 2008 04:45:50 +0000 Subject: [PATCH] Add thread alt classes. see #7635 git-svn-id: https://develop.svn.wordpress.org/trunk@8962 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/comment-template.php | 38 +++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/wp-includes/comment-template.php b/wp-includes/comment-template.php index eb1e8811a1..fa86339604 100644 --- a/wp-includes/comment-template.php +++ b/wp-includes/comment-template.php @@ -247,7 +247,7 @@ function comment_class( $class = '', $comment_id = null, $post_id = null, $echo * @return array Array of classes */ function get_comment_class( $class = '', $comment_id = null, $post_id = null ) { - static $comment_alt; + global $comment_alt, $comment_depth, $comment_thread_alt; $comment = get_comment($comment_id); @@ -269,6 +269,10 @@ function get_comment_class( $class = '', $comment_id = null, $post_id = null ) { if ( empty($comment_alt) ) $comment_alt = 0; + if ( empty($comment_depth) ) + $comment_depth = 1; + if ( empty($comment_thread_alt) ) + $comment_thread_alt = 0; if ( $comment_alt % 2 ) { $classes[] = 'odd'; @@ -279,6 +283,19 @@ function get_comment_class( $class = '', $comment_id = null, $post_id = null ) { $comment_alt++; + // Alt for top-level comments + if ( 1 == $comment_depth ) { + if ( $comment_thread_alt % 2 ) { + $classes[] = 'thread-odd'; + $classes[] = 'thread-alt'; + } else { + $classes[] = 'thread-even'; + } + $comment_thread_alt++; + } + + $classes[] = "depth-$comment_depth"; + if ( !empty($class) ) { if ( !is_array( $class ) ) $class = preg_split('#\s+#', $class); @@ -882,6 +899,8 @@ class Walker_Comment extends Walker { var $db_fields = array ('parent' => 'comment_parent', 'id' => 'comment_ID'); function start_lvl(&$output, $depth, $args) { + $GLOBALS['comment_depth'] = $depth + 1; + switch ( $args['style'] ) { case 'div': break; @@ -896,6 +915,8 @@ class Walker_Comment extends Walker { } function end_lvl(&$output, $depth, $args) { + $GLOBALS['comment_depth'] = $depth + 1; + switch ( $args['style'] ) { case 'div': break; @@ -911,6 +932,7 @@ class Walker_Comment extends Walker { function start_el(&$output, $comment, $depth, $args) { $depth++; + $GLOBALS['comment_depth'] = $depth; if ( !empty($args['callback']) ) { call_user_func($args['callback'], $comment, $args, $depth); @@ -920,10 +942,13 @@ class Walker_Comment extends Walker { $GLOBALS['comment'] = $comment; extract($args, EXTR_SKIP); - if ( 'div' == $args['style'] ) + if ( 'div' == $args['style'] ) { $tag = 'div'; - else + $add_below = 'comment'; + } else { $tag = 'li'; + $add_below = 'div-comment'; + } ?> < id="comment-"> @@ -943,7 +968,7 @@ class Walker_Comment extends Walker {
- 'div-comment', 'depth' => $depth, 'max_depth' => $args['depth'])) ?> + $add_below, 'depth' => $depth, 'max_depth' => $args['depth'])) ?>
@@ -976,7 +1001,10 @@ class Walker_Comment extends Walker { * @param $comments array Optional array of comment objects. Defaults to $wp_query->comments */ function wp_list_comments($args = array(), $comments = null ) { - global $wp_query; + global $wp_query, $comment_alt, $comment_depth, $comment_thread_alt; + + $comment_alt = $comment_thread_alt = 0; + $comment_depth = 1; $defaults = array('walker' => null, 'depth' => '', 'style' => 'ul', 'callback' => null, 'end-callback' => null, 'type' => 'all', 'page' => get_query_var('cpage'), 'per_page' => '');