Highlight Author Comments in WordPress, The Easier Right Way
->
I just came across a post published today which goes over “the right way” to highlight author comments in WordPress. Basically, instead of the usual code that inserts the “admincomment” class for just the first user (user ID 1). In the post, that code is adapted for any post author, no matter what the user ID is, which can be especially useful to multi-author blogs.
Ever since WordPress 2.7 was released over a year ago, a new function was introduced to display comments called wp_list_comments which is known for supporting threaded comments as well. In addition to threaded commments, it also outputs a class automatically which can be used to style author comments in WordPress 2.7.
Screencast
In this screencast, I go over the various classes added to a comment made by a post author. I also go over how to style the .bypostauthor
class.
Code Examples in Video:
.bypostauthor { background: #000; }
/* Sets a black background on post author comments. */.bypostauthor { background: #000 !important; }
/* Overrides any other background colors. */.commentlist .bypostauthor { background: #000; }
/* Another way to override other background colors (depends on how your theme is coded) */
In case you’re wondering, I was using the Firebug Firefox extension to inspect the element as well as test out the CSS code. Definitely a must-have addon for coders.
Custom Callback?
If you’re using a custom callback in conjunction with wp_list_comments, all you need to do is make sure the comment_class function is present in your callback, which will generate the same classes on each comment.
For an example of this, check out ThemeShaper’s tutorial on creating a comments template, check out where <?php comment_class() ?>
is added, and copy it in the same place of your own custom callback (assuming it’s not already there).
Conclusion
If you’re using an outdated theme that does not use wp_list_comments, the code from the first link should be just fine. If you’re using wp_list_comments, this is a much better and easier solution to implement, as you probably won’t have to modify any PHP in your theme (unless of course you have a custom callback).
Anyway, hope you liked the CSS tip. Let me know what you think in the comments. Also, do you prefer screencasts plus text, or just text?
Related posts:
- Change Your WordPress Author Name…Please
- Spectacu.la Releases Threaded Comments Plugin
- WordPress Weekend Resources: September 11, 2009
Posted in Theme Labs