Highlighting author comments on Wordpress
When I was looking for a way to highlight the author comments in this wordpress template I was creating, I had a search on google. Most of the results were just comparing the comment author email with a few hard-coded strings. I’m not sure if there is a specific reason for that, but I don’t think it is a good idea.
Say this was implemented in a template. Anyone using that template would have to go in and fiddle about with code to get it working. They would need to enter their email in the correct template file. Not everyone would be comfortable with that.
I went with comparing the comment author email directly with the blog author email, as follows:
<?php $commentClass = ( ( $comment->user_id == get_the_author_id() ) ? 'author_comment' : ('comment_item' . $oddcomment) ); ?>
<div class="<?php echo $commentClass ?>" id="comment-<?php comment_ID() ?>">
In the above code fragment, $oddcomment is either evaluated to '_alt' or an emtpy string.
So, if it is an author comment your class becomes author_comment, otherwise it is either comment_item or comment_item_alt depending on whether it is an odd numberd or even numbered comment. You can easily change this code to have the same odd/even effect on author comments too.
If you use this in your template, the blog authors using this template will not need to enter their email in a php file to get their comments highlighted. It will just work!
Get Email updates











Comments
Be the first to comment.
Pingbacks/Trackbacks
[...] Full Article: Highlighting author comments on WordPress [...]