Sandbox theme for WordPress makes it easy to style author comments without the need for plugins or template modifications. more →
Comment styling using Sandbox theme for Wordpress. Comments by me are labelled "The Author"
There are lots of advantages to designing websites with Cascading Style Sheets. CSS is relatively easy to learn and certainly easy to rework once a basic site framework has been established. Individual webpages or sections can easily be changed into something different just by swapping a single CSS file, or a line within a CSS file. The genius behind the Sandbox theme for WordPress is that it leverages CSS to let you change complex WordPress functions – functions that used to require changing the code or installing a plugin. In this post, I’ll show how you can use Sandbox’s comment classes to highlight authors’ comments with just a few lines of CSS.
Sandbox’s Semantic Classes
Sandbox is unique among WordPress themes because of its rich semantic markup and its elegant, dynamic class-generating functions. One opportunity this affords is the ability to add special styling to comments made by the author or other registered users, all without the use of plugins or theme modifications. Unique styling for comments helps reassure visitors that they can trust a comment was in fact made by you, and not by someone pretending to be you. In fact, Sandbox lets you distinguish comments made by the post’s author from other authors, and registered from unregistered users and from each other. This bit of magic comes via the use of comments class-generating functions that adds the following semantic classes to each comment li tag: “bypostauthor”, “postbyuser”, and “comment-author-[name].”
Now, just add styling:
/*common style for all comments*/
div#comments div#comments-list ol li {
list-style:none;
margin:0 -1em;
padding:1em;
}
/*style for alternating comments*/
div#comments div#comments-list ol li.alt {
background:#fff/;
border-top:1px solid #e4e4e4;
border-bottom:1px solid #e4e4e4;
}
/*style for author comments*/
div#comments div#comments-list ol li.bypostauthor div.comment-author:after{
font-style:italic;
content:"The Author";
margin-left:1em;
}
In this example, I’ve use the :after pseudo-class, which displays “The Author” after the comment li element, but only if you are using a modern browser like Mozilla/Firefox and Opera 7+, and IE7+. If you are still using Internet Explorer 6, then you’ll just have to trust me :-)
The Sandbox Designs Competition is an excellent place to learn how to make good use of Sandbox’s markup, and learn some advanced CSS techniques. For example, in her Sandbox theme Diurnal, Carolyn Smith cleverly exploits the class that displays the current hour when you are viewing a page. (See the demo). The page changes with the daylight.
If You Don’t Use Sandbox
Few, if any, WordPress themes come with such rich semantic markup and profusion of classes that Sandbox does. But in the huge community that is WordPress, you would expect alternatives. And there are. K2, which is technically not a theme but an advanced WordPress template, also offers a way to distinguish multiple users, as Paul Stamatiou explains. Or, you can use Jonathan Leighton’s Author Highlight plugin to add the required class attributes, which then need styling. Alternatively, you can modify the WordPress comment loop yourself to assign unique classes. Derek Punsalan offers a particularly thorough tutorial that shows you how to add classes based on the author’s email address. Or give your comments.php a complete makeover à la Chris Montoya that adds author highlighting and much more. But, really, Sandbox makes it easy.
While the instructions in this post are still valid, you no longer need to use a theme like Sandbox to give a special style to author comments. WordPress 2.7 automatically adds a CSS class to author and registered users comments. To make use of them, add your styles to your style.css:
/* comment selectors in WordPress 2.7+ */
li.bypostauthor {
/* add CSS styles for author comments */
}
li.byuser {
/* add CSS styles for registered users comments */
}
Style Author Comments with WordPress Sandbox Theme
Sandbox theme for WordPress makes it easy to style author comments without the need for plugins or template modifications. more →
Comment styling using Sandbox theme for Wordpress. Comments by me are labelled "The Author"
Tags
conversations, WordPress
In This Series
Customize Your Blog
There are lots of advantages to designing websites with Cascading Style Sheets. CSS is relatively easy to learn and certainly easy to rework once a basic site framework has been established. Individual webpages or sections can easily be changed into something different just by swapping a single CSS file, or a line within a CSS file. The genius behind the Sandbox theme for WordPress is that it leverages CSS to let you change complex WordPress functions – functions that used to require changing the code or installing a plugin. In this post, I’ll show how you can use Sandbox’s comment classes to highlight authors’ comments with just a few lines of CSS.
Sandbox’s Semantic Classes
Sandbox is unique among WordPress themes because of its rich semantic markup and its elegant, dynamic class-generating functions. One opportunity this affords is the ability to add special styling to comments made by the author or other registered users, all without the use of plugins or theme modifications. Unique styling for comments helps reassure visitors that they can trust a comment was in fact made by you, and not by someone pretending to be you. In fact, Sandbox lets you distinguish comments made by the post’s author from other authors, and registered from unregistered users and from each other. This bit of magic comes via the use of comments class-generating functions that adds the following semantic classes to each comment li tag: “
bypostauthor”, “postbyuser”, and “comment-author-[name].”Now, just add styling:
In this example, I’ve use the
:afterpseudo-class, which displays “The Author” after the commentlielement, but only if you are using a modern browser like Mozilla/Firefox and Opera 7+, and IE7+. If you are still using Internet Explorer 6, then you’ll just have to trust me :-)The Sandbox Designs Competition is an excellent place to learn how to make good use of Sandbox’s markup, and learn some advanced CSS techniques. For example, in her Sandbox theme Diurnal, Carolyn Smith cleverly exploits the class that displays the current hour when you are viewing a page. (See the demo). The page changes with the daylight.
If You Don’t Use Sandbox
Few, if any, WordPress themes come with such rich semantic markup and profusion of classes that Sandbox does. But in the huge community that is WordPress, you would expect alternatives. And there are. K2, which is technically not a theme but an advanced WordPress template, also offers a way to distinguish multiple users, as Paul Stamatiou explains. Or, you can use Jonathan Leighton’s Author Highlight plugin to add the required class attributes, which then need styling. Alternatively, you can modify the WordPress comment loop yourself to assign unique classes. Derek Punsalan offers a particularly thorough tutorial that shows you how to add classes based on the author’s email address. Or give your comments.php a complete makeover à la Chris Montoya that adds author highlighting and much more. But, really, Sandbox makes it easy.
While the instructions in this post are still valid, you no longer need to use a theme like Sandbox to give a special style to author comments. WordPress 2.7 automatically adds a CSS class to author and registered users comments. To make use of them, add your styles to your style.css: