Forums

How to create Loop condition with the_author_*? (3 posts)

  1. questiongirl
    Member
    Posted 3 years ago #

    I'm in the Loop and trying to control an echo statement based on the author of the post but the condition is never true. And it prints the ID on the page. What is the correct way to evaluate the_author_login or some other template tag?

    <?php
    if (the_author_login() == 2) {
    echo "<div class=\"entry3\">" ;
    }

    else { echo "<div class=\"entry\">";

    } ?>

  2. MichaelH
    moderator
    Posted 3 years ago #

    I believe you should use the_author_ID instead of the_author_login.
    http://codex.wordpress.org/Template_Tags/the_author_ID

  3. questiongirl
    Member
    Posted 3 years ago #

    Hi Michael,
    Sorry for the typo in my example. Yes I tried the_author_ID, and it prints the 2 on the page. But the value it returns in PHP is false, not 2, so the statement is never executed. With the_author_login I tried == to "admin" or admin and it is also always false even though it prints admin on the page.

    Thanks.

Topic Closed

This topic has been closed to new replies.

About this Topic