What about this <?php the_author_email(); ?>?
I tried that – unfortunately, that somehow breaks the php script, and ends up echoing the variable onto the website, rather than just placing itself into my script. I think that’s why scriptygoddess used the $comments variable to get the comment email, rather than one of the WP template tags.
Anyone know the variable I can use to get the post author’s email?
If you find a solution let me know, as I will be trying something similar. You could try the offical commetns plugin, but I’m not sure if that will highlight the admin comments, or that of the authors
<?php
$authorcomment = '';
if($comment->comment_author_email == get_the_author_email()) {
$authorcomment = ' authorcomment';
}
?>
Not good form to mix boolean and string types for a variable value (hence the reason for “$authorcomment = ''“).
Aha! I found my solution!
<?php
global $authordata;
$authorcomment = false;
if($comment->comment_author_email == $authordata->user_email) {
$authorcomment = ' authorcomment';
}
?>
I had to set the global variable first, or the $authordata var didn’t exist, but this is working for me!
get_the_author_email() takes care of the global for you.
Awesome, thanks for the tip! So, for my notes, here’s the final code:
<?php
$authorcomment = '';
if($comment->comment_author_email == get_the_author_email()) {
$authorcomment = ' authorcomment';
}
?>
The author highlight also worked for me, but I’d like to have 2 different highlights, one for the author and another gor the other comments posted by visitors…. how can I do so?
So I just paste the following code somewhere. Does anything else need to be filled out?
<?php
$authorcomment = '';
if($comment->comment_author_email == get_the_author_email()) {
$authorcomment = ' authorcomment';
}
?>
So where would this code go? WordPress 1.5.
Hi I’m also trying to use this code but I have no idea where to put it, can someone please tell me where it should go?
I’m using a Kubrick-based theme (Letterhead), and while this code seems to work fine (nice job BTW), it doesn’t seem to want to supercede the alt class comment colors no matter what I do. Anyone else having an issue with this? Any workaround ideas?
For example, if I post a comment as the author, it will give me my special author class for the comment only if the alt class is not set in the comment loop with the variable $oddcomment. When $oddcomment is set to alt, I’ll get a grey box instead of the expected yellow author highlight. If $oddcomment is not set to alt, then I can get the author highlight. The value of $oddcomment alternates with every iteration of the comment loop. I’ve tried using a conditional to put priority on the author class, but no luck.
My code showing my simple hack that doesn’t work:
<?php
$authorcomment = '';
if($comment->comment_author_email == get_the_author_email()) {
$authorcomment = 'me'; }
?>
<li class="<?php
// MY HACK HERE:
if ($authorcomment=='me') echo $authorcomment;
else echo $oddcomment;
?>" id="comment-<?php comment_ID() ?>">