Comment Highlighting (based on author)
Monty asked about comment highlighting based on author.
Even though this isn't a plugin, I thought this could work similar to the way I was doing comment highlighting
Again, after your comment loop:
<?php foreach ($comments as $comment) { ?>
Add the following (with edits as neccessary) :
<?php
$isByAuthor = false;
if($comment->comment_author_email == 'YOUR-EMAIL') {
$isByAuthor = true;
}
?>
Then before your comment text begins (with <?php comment_text() ?>) add this:
<?php if($isByAuthor ) { echo '<div class="authorcomment">';} ?>
To close the DIV tag - BEFORE the ending LI tag for the comment add this
<?php if($isByAuthor ) { echo '</div>';} ?>
Then add a style "authorcomment" to your style sheet. Style however you like.
Then as long as you use that email when you comment - the comment will be highlighted.
See alternate (simplified) variations in the comments
June 22nd, 2004 at 2:32 am
I mentioned Jenn's WordPress additions on Scriptygoddess yesterday, but she has several standouts in her subcategories that are definitely worthy of a mention on their own. A sampling of her recent efforts:
June 22nd, 2004 at 3:17 am
Because the e-mail field is never displayed publicly, it can be used as a password of sort. A poor man's authentication, if you will. I use this to add a little badge next to comments I make on my own site (did this with Movable Type as well). A little PHP logic checks to see if the e-mail address matches my secret "password" e-mail address, and if it does, it knows it is me. This is a good way to avoid confusion when you only use your first name to post comments, or when some clown thinks they can impersonate you on your own site.
June 22nd, 2004 at 8:22 am
Actually - you're right - I guess it could be simplified to just check email… Can you see any other reason to have it check all three? (if not, I'll update the post)
June 22nd, 2004 at 8:35 pm
Can't think of a reason to have it check all three, especially since the other two (URI and Name) are publicly visible. Heck, I can think of a good reason NOT to have it check all three. Say you're at a library where your comment posting cookie isn't saved, and you put down your URL without the trailing slash, and that causes the if() logic to fail.
June 22nd, 2004 at 9:03 pm
Very true. Post has been updated.
June 28th, 2004 at 1:20 am
Thank you so much Jennifer
July 3rd, 2004 at 8:50 am
Here's the code I use to add a badge next to comments I leave on my own blog.
You basically just make up a fake secret e-mail address and use that to post comments:
<?php
if($comment->comment_author_email == 'my_secret_address@mydomain.com'){ ?>
<span class="blogauthor">
<?php } else { ?>
<span class="comment-author">
<?php } ?>
<?php comment_author_link(); ?></span>
Then all you have to do is style "blogauthor" and "comment-author" differently. To add a badge, you would do something like this in your CSS:
.blogauthor { background-image:url(http://www.domain.com/images/blog_author.gif);
background-position:right;
background-repeat:no-repeat;
padding-right:80px;
}
July 4th, 2004 at 7:50 am
My code for this is slightly different because I'm not using classes, etc. - and I've actually simplified it from the original post…
(Code in italic already exists)
<?php comment_author_link() ?>
<?php if ($comment->comment_author_email == 'MyEmailAddress@example.com') {
echo '<img src="/images/author.gif" width="64" height="9">';
} ?>
<?php comment_date() ?>
July 7th, 2004 at 7:23 pm
How did you modify your badge code, Jennifer, to include the subscriber badge as well?
July 7th, 2004 at 7:29 pm
The code for both is here.
July 7th, 2004 at 8:01 pm
Rather than ping ScriptyGoddess multiple times and clog my sideblog with even more WordPress links, I decided to plop 'em all here. I'm going to give WordPress a try again on my course website, since there are various hacks that…
July 9th, 2004 at 8:38 am
Thank you! You are so punk rock.
July 12th, 2004 at 10:02 am
I am utilizing the Comment Highlighting and I am also using your Drop-Down Comments. But it only highlights my comments when someone clicks on the "Add Comment" page. If you go to "Show Comment"…my comments (as the author) does not get highlighted. Do I have to add this code to my dropdown-comments.php for it to work when someone clicks on "Show Comments"
July 14th, 2004 at 7:52 am
Poonam - yes - you need to add the code to every "comment" page you're using.
July 14th, 2004 at 8:08 pm
Thanks Jennifer for the info!
August 11th, 2004 at 2:55 pm
One more question Jennifer - are you able to manipulate this code so that if you have multiple authors (two) for one blog..then they can have different colors.
For instance, I would have color silver and my husband would have yellow color.
Thanks!
August 12th, 2004 at 8:45 pm
Poonam- try this:
<?php
if ($comment->comment_author_email == 'author1email@example.com') {
echo '<img src="/images/author1.gif" width="64" height="9">';
} else if ($comment->comment_author_email == 'author2email@example.com') {
echo '<img src="/images/author2.gif" width="64" height="9">';
}
?>
etc. etc. (just keeping adding else ifs for as many authors/author email addresses there are)
August 13th, 2004 at 12:37 am
Thanks Jennifer! I have some questions.
So does this go along with the code that you have shown..or do i take all of that out and put this in?
Then in my css, I have so do I keep that..or no?
Lastly, what's the image source for images/author2.gif? Do i need to add something to my images folder?
Thank you in advance.
September 25th, 2004 at 8:28 pm
September 26th, 2004 at 4:00 pm
Is there an actually plugin/hack for this with instructions that I may add to my website?
If there is, could it be e-mailed to me?
Thanks.
September 26th, 2004 at 9:44 pm
Kirrin - This post recently pinged mine saying they had created a plugin (rather than edit code like my post instructed). I haven't tried it, so I can't speak to it, but maybe that's what you were looking for?
October 6th, 2004 at 11:39 am
I just used this technique on my site which works great - however does not prevent spoofing. Someone mentioned that the e-mail address is not shown, but it is (even in this page, I see the email field) so I'm not sure what is being referred to. If I am showing the e-mail field - I can't prevent someone from filling in my information and spoofing me.
Is there some way I can restrict it to a certain IP address or some other technique?
Thanks!
Tom
October 6th, 2004 at 11:50 am
Tom - the point is that someone who doesn't already know your email address can not derive it from the page shown to them. While the FIELD is there for you to fill out, the data is not relayed back on the page. And even if they do know your address - you can use a seperate "special" one just for when you fill out comments on your own blog (sort of like a "password").
October 6th, 2004 at 11:54 am
Oh! Good heavens I kept thinking of the form itself - not the display of the comments. Gee is my face red!
So I get you, I can use one of my Yahoo! AddressGuard emails for example, that nobody knows, so nobody would ever be able to spoof me (barring they don't guess it) correct?
Thanks!
December 1st, 2004 at 9:26 pm
December 10th, 2004 at 3:27 am
December 13th, 2004 at 2:18 pm
March 12th, 2005 at 5:53 pm
I have a version that I modified for use on my site, where I have several authors posting, and I want each comments page to highlight the comments from the author of the post without hard-coding any email addresses:
<?php
global $authordata;
$authorcomment = false;
if($comment->comment_author_email == $authordata->user_email) {
$authorcomment = ' authorcomment';
}
?>
I hope this helps someone. I'm not a PHP guy at all, and it took beating my head against the wall for several hours to figure this out. Any suggestions, please let me know!
March 14th, 2005 at 2:49 pm
Improved version based on some feedback from the WP support forums:
<?php
$authorcomment = ";
if($comment->comment_author_email == get_the_author_email()) {
$authorcomment = ' authorcomment';
}
?>
March 15th, 2005 at 7:04 pm
Ok, wordpress newbie here, does this work in wp 1.5, I did a quick search thru the comments pages I have in my templates and didn't find < ?php foreach ($comments as $comment) { ?>, I'm wondering if this changed in wp 1.5 hmm..
March 15th, 2005 at 7:14 pm
Ok, please disregard my previous comment, but now I have an issue with using this with two authors, how do I apply seperate styles for different authors..?
April 9th, 2005 at 6:33 pm
This is great! I tried to use the plugin but it didn't work for me. Modifying a few lines of according to yor tutorial is so easy and works perrrfect!
Thanks again
April 16th, 2005 at 1:36 pm
I'm trying to use the code at my comments, but I'm having a little trouble. For example, the comments from my visitors have a yellow background, and I'd like mine to have a pink background… So when I copied the code, my comments came within a yellow cell (the default comments style) and then a pink cell (my comments). How can I separate my comments style to the others?
April 19th, 2005 at 10:59 pm
You might want to check out my site, I used this script to do some pretty cool stuff.. I think what you asking for.
http://www.chrisvschris.com