WordPress.org

Ready to get started?Download WordPress

Forums

highlight author comments (12 posts)

  1. spaceninja
    Member
    Posted 9 years ago #

    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?

  2. AsceticMonk
    Member
    Posted 9 years ago #

    What about this <?php the_author_email(); ?>?

  3. spaceninja
    Member
    Posted 9 years ago #

    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?

  4. Jinsan
    Member
    Posted 9 years ago #

    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

  5. Kafkaesqui

    Posted 9 years ago #

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

  6. spaceninja
    Member
    Posted 9 years ago #

    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!

  7. Kafkaesqui

    Posted 9 years ago #

    get_the_author_email() takes care of the global for you.

  8. spaceninja
    Member
    Posted 9 years ago #

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

  9. maryafernanda
    Member
    Posted 9 years ago #

    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?

  10. unfortunate
    Member
    Posted 8 years ago #

    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.

  11. nathan
    Member
    Posted 8 years ago #

    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?

  12. gazeglow
    Member
    Posted 8 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.