comment_class(). Props sandbox theme. see #7560

git-svn-id: http://svn.automattic.com/wordpress/trunk@8695 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2008-08-20 23:48:09 +00:00
parent ab71ccb00d
commit 9f9ef004db
3 changed files with 68 additions and 4 deletions

View File

@ -12,7 +12,7 @@
<ol id="commentlist">
<?php foreach ($comments as $comment) : ?>
<li id="comment-<?php comment_ID() ?>">
<li <?php comment_class(); ?> id="comment-<?php comment_ID() ?>">
<?php echo get_avatar( $comment, 32 ); ?>
<?php comment_text() ?>
<p><cite><?php comment_type(__('Comment'), __('Trackback'), __('Pingback')); ?> <?php _e('by'); ?> <?php comment_author_link() ?> &#8212; <?php comment_date() ?> @ <a href="#comment-<?php comment_ID() ?>"><?php comment_time() ?></a></cite> <?php edit_comment_link(__("Edit This"), ' |'); ?></p>

View File

@ -14,7 +14,7 @@
}
/* This variable is for alternating comment background */
$oddcomment = 'class="alt" ';
$oddcomment = 'alt';
?>
<!-- You can start editing here. -->
@ -26,7 +26,7 @@
<?php foreach ($comments as $comment) : ?>
<li <?php echo $oddcomment; ?>id="comment-<?php comment_ID() ?>">
<li <?php comment_class($oddcomment) ?>id="comment-<?php comment_ID() ?>">
<?php echo get_avatar( $comment, 32 ); ?>
<cite><?php comment_author_link() ?></cite> Says:
<?php if ($comment->comment_approved == '0') : ?>
@ -42,7 +42,7 @@
<?php
/* Changes every other comment to a different class */
$oddcomment = ( empty( $oddcomment ) ) ? 'class="alt" ' : '';
$oddcomment = ( empty( $oddcomment ) ) ? 'alt' : '';
?>
<?php endforeach; /* end for each comment */ ?>

View File

@ -218,6 +218,70 @@ function comment_author_url_link( $linktext = '', $before = '', $after = '' ) {
echo get_comment_author_url_link( $linktext, $before, $after );
}
/**
* Generates semantic classes for each comment element
*
* @since 2.7
*
* @param string|array $class One or more classes to add to the class list
* @param int $comment_id An optional comment ID
* @param int $post_id An optional post ID
*/
function comment_class( $class = '', $comment_id = null, $post_id = null ) {
// Separates classes with a single space, collates classes for post DIV
echo 'class="' . join( ' ', get_comment_class( $class, $comment_id, $post_id ) ) . '"';
}
/**
* Returns the classes for the comment div as an array
*
* @since 2.7
*
* @param string|array $class One or more classes to add to the class list
* @param int $comment_id An optional comment ID
* @param int $post_id An optional post ID
* @return array Array of classes
*/
function get_comment_class( $class = '', $comment_id = null, $post_id = null ) {
static $comment_alt;
$comment = get_comment($comment_id);
$classes = array();
// Get the comment type (comment, trackback),
$classes[] = $comment->comment_type;
// If the comment author has an id (registered), then print the log in name
if ( $comment->user_id > 0 && $user = get_userdata($comment->user_id) ) {
// For all registered users, 'byuser'
$classes[] = 'byuser comment-author-' . $user->user_nicename;
// For comment authors who are the author of the post
if ( $post = get_post($post_id) ) {
if ( $comment->user_id === $post->post_author )
$classes[] = 'bypostauthor';
}
}
if ( empty($comment_alt) )
$comment_alt = 0;
if ( $comment_alt % 2 )
$classes[] = 'odd';
else
$classes[] = 'even';
$comment_alt++;
if ( !empty($class) ) {
if ( !is_array( $class ) )
$class = preg_split('#\s+#', $class);
$classes = array_merge($classes, $class);
}
return apply_filters('comment_class', $classes, $class, $comment_id, $post_id);
}
/**
* Retrieve the comment date of the current comment.
*