WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Comparing 2 Functions (4 posts)

  1. wajih
    Member
    Posted 6 years ago #

    Hello!

    Well I'm trying to modify my comments.php file in order to change the background color (change the CSS of comments) so that if a regular user post a comment, a particular style will be applied, and if the author of the post itself replies (hence post), another style will be applied.

    Here is what I did, which does not work (keep in mind that I am completely new, even to PHP):

    <?php
    
    if( the_author() == comment_author )
        // then do this set of code
    
    else
       // then do that set of code.
    
    ?>

    So what it is doing, instead of of comparing the two, it is outputting (echo'ing) on the webpage. In this case, the_author is admin, and comment_author is also admin, and it is outputting adminadmin (1 word), and outputs the code which is in my else() statement.

    So am I doing wrong?

    Thanks for your help :)

  2. wajih
    Member
    Posted 6 years ago #

    I resolved it!

    I just replaced the_author() and comment_author() by get_the_author() and get_comment_author() respectively, and it works flawlessly :)

    CASE CLOSED :D

  3. drphil9001
    Member
    Posted 6 years ago #

    I believe that you want get_the_author() instead of the_author(). If you look at author_template.php you will see that the later echos the result of the former.

  4. spacebrew
    Member
    Posted 5 years ago #

    Can anyone suggest a way to do the same thing you're doing here, but for multiple authors?

    Basically what I want is for anyone who is a contributor or above, their comments are a certain class, where just subscribers have a separate style. Any help is appreciated.

Topic Closed

This topic has been closed to new replies.

About this Topic