• Using code from scriptygoddess, I’ve gotten my comments to highlight successfully. The problem is, I have multiple authors on my blog, and I only want to highlight the comments from the person who authored the post being viewed.

    Here’s what I have now:

    <?php
    $authorcomment = false;
    if($comment->comment_author_email == 'primary@email.com') {
    $authorcomment = ' authorcomment';
    } elseif($comment->comment_author_email == 'secondary@email.com') {
    $authorcomment = ' authorcomment';
    }
    ?>

    What I would like is to do something like this:

    <?php
    $authorcomment = false;
    if($comment->comment_author_email == $post->post_author_email) {
    $authorcomment = ' authorcomment';
    }
    ?>

    Obviously, the $post->post_author_email bit doesn’t exist, but I’m looking for something similar that will just output the email address for the author of the post, so that I can compare it to the author of the email.

    Anyone know how to do this?

Viewing 11 replies - 1 through 11 (of 11 total)
  • What about this <?php the_author_email(); ?>?

    Thread Starter spaceninja

    (@spaceninja)

    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 = ''“).

    Thread Starter spaceninja

    (@spaceninja)

    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.

    Thread Starter spaceninja

    (@spaceninja)

    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';
    }
    ?>

    maryafernanda

    (@maryafernanda)

    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() ?>">

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘highlight author comments’ is closed to new replies.