1
0
mirror of https://github.com/kremalicious/blog.git synced 2024-12-02 22:24:29 +01:00
blog/content/posts/2008-12-13-howto-styling-author-comments-with-wordpress-27.md

61 lines
2.9 KiB
Markdown
Raw Normal View History

2013-11-18 23:54:59 +01:00
---
2018-07-19 02:22:01 +02:00
type: post
2013-11-21 20:38:20 +01:00
2013-11-18 23:54:59 +01:00
title: 'HowTo: Styling Author Comments With Wordpress 2.7+'
2013-11-21 20:38:20 +01:00
author: Matthias Kretschmann
date: 2008-12-13 16:47:43+00:00
2018-07-18 23:04:31 +02:00
2013-11-18 23:54:59 +01:00
tags:
2018-08-30 22:50:09 +02:00
- design
2015-06-07 23:13:18 +02:00
- tutorial
- wordpress
2017-11-25 17:24:23 +01:00
coinhive: true
2013-11-18 23:54:59 +01:00
---
2018-07-17 23:26:36 +02:00
![Wordpress Logo by kremalicious](../media/wordpress-logo.png)
2013-11-18 23:54:59 +01:00
Since my update to Wordpress 2.7 I'm pretty much into all the new comments stuff. As [I've written before](http://www.kremalicious.com/2008/12/how-to-set-a-custom-gravatar-image-in-wordpress-27/), the comment functionality changed dramatically with Wordpress 2.7. This makes writing a comments template much easier but if you used Worpress prior to 2.7 you have to change some things to work again. Beside other things this includes [Gravatar styling](http://www.kremalicious.com/2008/12/how-to-set-a-custom-gravatar-image-in-wordpress-27/) and also adding different styling to comments from the author of an article. In this article I will show you how to realize the latter with Wordpress 2.7 and above.
2018-08-08 22:26:42 +02:00
<!-- more -->
2013-11-18 23:54:59 +01:00
Let's start by looking at the code to achieve styling of author comments prior to Wordpress 2.7. On kremalicious.com I've used this code:
2014-09-10 20:13:28 +02:00
2018-07-18 23:04:31 +02:00
```php
2014-09-10 20:13:28 +02:00
<li class="
2015-06-07 23:00:52 +02:00
<?php
if ($comment->comment_author_url == "http://www.kremalicious.com")
echo 'author';
else echo $oddcomment;
?>
2014-09-10 20:13:28 +02:00
item" id="comment-<?php comment_ID() ?>">
<em>other comments code</em>
</li>
2018-07-18 23:04:31 +02:00
```
2015-06-07 23:00:52 +02:00
2013-11-21 20:38:20 +01:00
So with some php stuff we were able to check for the author name or, as I did it, for the URL of the comment author. If one of these were detected Wordpress added a new class 'author' to the `<li>` tag which we were able to style by adding a li.author to our css file:
2015-06-07 23:00:52 +02:00
2018-07-18 23:04:31 +02:00
```css
li.author { /* css comes in here */ }
```
2013-11-18 23:54:59 +01:00
2013-11-21 20:38:20 +01:00
But with Wordpress 2.7 these steps are needless because of the [new function `<?php wp_list_comments(); ?>`](http://codex.wordpress.org/Template_Tags/wp_list_comments) which adds a class on author comments for itself!
2013-11-18 23:54:59 +01:00
2015-06-07 23:00:52 +02:00
If a comment from the author of an article is posted under this article, **Wordpress automatically adds the class 'bypostauthor' to the surrounding `<li>` tag.** So all you have to do is adding a css style of `li.bypostauthor` to your css file or just renaming your old `li.author` class or whatever you used for this:
2013-11-18 23:54:59 +01:00
2018-07-18 23:04:31 +02:00
```css
li.bypostauthor { /* css comes in here */ }
```
2013-11-18 23:54:59 +01:00
And that's it for adding a different style to comments from the article author. Just add some css and there you go. Wonderful!
## Even more
Wordpress also has a special class for registered users of your site so you're able to style their comments as well. For this just use the class 'byuser':
2018-07-18 23:04:31 +02:00
```css
li.byuser { /* css comes in here */ }
```
2013-11-18 23:54:59 +01:00
2015-06-07 23:00:52 +02:00
All the various classes Wordpress adds to comments are listed [in the Codex page for enhanced comments display](http://codex.wordpress.org/Migrating_Plugins_and_Themes_to_2.7/Enhanced_Comment_Display#CSS_Styling). And [here's a very nice grahical overview about everything Wordpress 2.7 adds to comments](http://www.wp-fun.co.uk/2008/12/10/27-comment-classes/).