Add thread alt classes. see #7635
git-svn-id: http://svn.automattic.com/wordpress/trunk@8962 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
04ce449e3c
commit
d736c3459f
|
@ -247,7 +247,7 @@ function comment_class( $class = '', $comment_id = null, $post_id = null, $echo
|
||||||
* @return array Array of classes
|
* @return array Array of classes
|
||||||
*/
|
*/
|
||||||
function get_comment_class( $class = '', $comment_id = null, $post_id = null ) {
|
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);
|
$comment = get_comment($comment_id);
|
||||||
|
|
||||||
|
@ -269,6 +269,10 @@ function get_comment_class( $class = '', $comment_id = null, $post_id = null ) {
|
||||||
|
|
||||||
if ( empty($comment_alt) )
|
if ( empty($comment_alt) )
|
||||||
$comment_alt = 0;
|
$comment_alt = 0;
|
||||||
|
if ( empty($comment_depth) )
|
||||||
|
$comment_depth = 1;
|
||||||
|
if ( empty($comment_thread_alt) )
|
||||||
|
$comment_thread_alt = 0;
|
||||||
|
|
||||||
if ( $comment_alt % 2 ) {
|
if ( $comment_alt % 2 ) {
|
||||||
$classes[] = 'odd';
|
$classes[] = 'odd';
|
||||||
|
@ -279,6 +283,19 @@ function get_comment_class( $class = '', $comment_id = null, $post_id = null ) {
|
||||||
|
|
||||||
$comment_alt++;
|
$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 ( !empty($class) ) {
|
||||||
if ( !is_array( $class ) )
|
if ( !is_array( $class ) )
|
||||||
$class = preg_split('#\s+#', $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');
|
var $db_fields = array ('parent' => 'comment_parent', 'id' => 'comment_ID');
|
||||||
|
|
||||||
function start_lvl(&$output, $depth, $args) {
|
function start_lvl(&$output, $depth, $args) {
|
||||||
|
$GLOBALS['comment_depth'] = $depth + 1;
|
||||||
|
|
||||||
switch ( $args['style'] ) {
|
switch ( $args['style'] ) {
|
||||||
case 'div':
|
case 'div':
|
||||||
break;
|
break;
|
||||||
|
@ -896,6 +915,8 @@ class Walker_Comment extends Walker {
|
||||||
}
|
}
|
||||||
|
|
||||||
function end_lvl(&$output, $depth, $args) {
|
function end_lvl(&$output, $depth, $args) {
|
||||||
|
$GLOBALS['comment_depth'] = $depth + 1;
|
||||||
|
|
||||||
switch ( $args['style'] ) {
|
switch ( $args['style'] ) {
|
||||||
case 'div':
|
case 'div':
|
||||||
break;
|
break;
|
||||||
|
@ -911,6 +932,7 @@ class Walker_Comment extends Walker {
|
||||||
|
|
||||||
function start_el(&$output, $comment, $depth, $args) {
|
function start_el(&$output, $comment, $depth, $args) {
|
||||||
$depth++;
|
$depth++;
|
||||||
|
$GLOBALS['comment_depth'] = $depth;
|
||||||
|
|
||||||
if ( !empty($args['callback']) ) {
|
if ( !empty($args['callback']) ) {
|
||||||
call_user_func($args['callback'], $comment, $args, $depth);
|
call_user_func($args['callback'], $comment, $args, $depth);
|
||||||
|
@ -920,10 +942,13 @@ class Walker_Comment extends Walker {
|
||||||
$GLOBALS['comment'] = $comment;
|
$GLOBALS['comment'] = $comment;
|
||||||
extract($args, EXTR_SKIP);
|
extract($args, EXTR_SKIP);
|
||||||
|
|
||||||
if ( 'div' == $args['style'] )
|
if ( 'div' == $args['style'] ) {
|
||||||
$tag = 'div';
|
$tag = 'div';
|
||||||
else
|
$add_below = 'comment';
|
||||||
|
} else {
|
||||||
$tag = 'li';
|
$tag = 'li';
|
||||||
|
$add_below = 'div-comment';
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
<<?php echo $tag ?> <?php comment_class() ?> id="comment-<?php comment_ID() ?>">
|
<<?php echo $tag ?> <?php comment_class() ?> id="comment-<?php comment_ID() ?>">
|
||||||
<?php if ( 'list' == $args['style'] ) : ?>
|
<?php if ( 'list' == $args['style'] ) : ?>
|
||||||
|
@ -943,7 +968,7 @@ class Walker_Comment extends Walker {
|
||||||
<?php echo apply_filters('comment_text', get_comment_text()) ?>
|
<?php echo apply_filters('comment_text', get_comment_text()) ?>
|
||||||
|
|
||||||
<div class='reply'>
|
<div class='reply'>
|
||||||
<?php echo comment_reply_link(array('add_below' => 'div-comment', 'depth' => $depth, 'max_depth' => $args['depth'])) ?>
|
<?php echo comment_reply_link(array('add_below' => $add_below, 'depth' => $depth, 'max_depth' => $args['depth'])) ?>
|
||||||
<?php if ( 'list' == $args['style'] ) : ?>
|
<?php if ( 'list' == $args['style'] ) : ?>
|
||||||
</div>
|
</div>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
@ -976,7 +1001,10 @@ class Walker_Comment extends Walker {
|
||||||
* @param $comments array Optional array of comment objects. Defaults to $wp_query->comments
|
* @param $comments array Optional array of comment objects. Defaults to $wp_query->comments
|
||||||
*/
|
*/
|
||||||
function wp_list_comments($args = array(), $comments = null ) {
|
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',
|
$defaults = array('walker' => null, 'depth' => '', 'style' => 'ul', 'callback' => null, 'end-callback' => null, 'type' => 'all',
|
||||||
'page' => get_query_var('cpage'), 'per_page' => '');
|
'page' => get_query_var('cpage'), 'per_page' => '');
|
||||||
|
|
Loading…
Reference in New Issue