Hello,
Welcome to my first tech post. Hopefully this will make sense and be useful.
In the past few days I have been hunting around for comment styling for WordPress. I have found some really great articles but no solid here’s some code and have fun with it posts. So I have put together a copy and paste version of the comments style on this blog.
Wordpress enables you to have custom comments by use of callbacks. See here for a great post and where I learnt a lot about the wp_list_comments function. http://www.studiograsshopper.ch/code-snippets/customising-wp_list_comments/
Ok, so here’s the code bit:
Firstly we add a new function (themeComments) to the functions.php file, you’ll see I’ve added in some new div tags in so we can style the comments a little easier
function themeComments($comment, $args, $depth) {
$GLOBALS['comment'] = $comment; ?>
<li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
<div id="comment-<?php comment_ID(); ?>">
<div class="comment-author vcard">
<div class="comment-by">
<?php printf(__('<cite class="fn">%s</cite><br /><span class="says">says:</span>'), get_comment_author_link()) ?>
</div>
<div class="comment-avatar">
<?php echo get_avatar($comment,$size='48' ); ?>
</div>
</div>
<div class="commentsWrapper">
<?php if ($comment->comment_approved == '0') : ?>
<em><?php _e('Your comment is awaiting moderation.') ?></em>
<br />
<?php endif; ?>
<div class="comment-meta commentmetadata"><a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ?>"><?php printf(__('%1$s at %2$s'), get_comment_date(), get_comment_time()) ?></a><?php edit_comment_link(__('(Edit)'),' ','') ?></div>
<?php comment_text() ?>
<div class="reply">
<?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
</div>
</div>
<div class="commentSpeech"></div>
</div>
<?php
}
In the comments.php we add in the wp_list_comments params to the callback function and tell wp_list_comments that this is a comment type.
wp_list_comments('type=comment&callback=themeComments');
Then all we need to do is some nice CSS to handle the new code. I've done everything with percentages so you don't need to continually create new styles to cope with different depths of comments. I've tested it down to 10 replies and it still works.
Also all this CSS has resets applied, so if you're not using a reset it will need tweaking.
.comment{
width:100%;
margin-bottom:20px;
clear:both;
}
.comment-meta{
width:98%;
padding-bottom:5px;
border-bottom:1px dashed #ccc;
font-size:0.9em;
}
.comment-reply-link{
display:inline-block;
padding:5px;
background-color:black;
color:white;
font-family:Verdana,Arial,Helvetica,sans-serif;
margin-top:20px;
}
.comment-meta a{
color:#666;
}
.comment-by cite{
font-weight:bold;
}
.comment-by{
display:block;
position:relative;
padding-top:10px;
padding-bottom:10px;
top:0;
text-align:left;
float:left;
}
.comment-avatar{
display:block;
padding-top:10px;
padding-bottom:10px;
float:left;
clear:both;
border-top:1px dashed #ccc;
}
.commentlist{
margin:0;
padding:0;
margin-top:20px;
margin-bottom:50px;
padding-bottom:50px;
}
.commentlist ul,.commentlist li{
list-style-type:none;
position:relative;
}
.children{
padding-left:20px;
}
.comment-author{
position:relative;
width:10%;
float:left;
display:inline-block;
margin-bottom:20px;
margin-bottom:20px;
border-left:2px solid #009999;
padding-left:10px;
}
.commentSpeech{
float:right;
width:10px;
display:inline-block;
background-image:url('_/images/leftArrow.gif');
background-repeat:no-repeat;
background-position:0px 10px;
height:100%;
min-height:73px;
}
.children .comment .commentsWrapper{
background-color:#f5f5f5;
}
.commentsWrapper{
float:right;
padding:10px;
border:1px solid #ccc;
width:81%;
display:inline-block;
margin-bottom:20px;
-moz-box-shadow:2px 2px #eee;
-webkit-box-shadow:2px 2px #eee;
box-shadow:2px 2px #eee;
}
And that's it, enjoy!