• Resolved nvw

    (@mskopel)


    Hello,

    I am trying to set up an if statement at the bottom of single.php which says that if the author is “Barbara”, show the sidebar, otherwise show a different sidebar. The code is working but the_author is showing at the top of the either side bar. I am pretty sure this is to be expected but I am not sure how to get around it. Can someone offer an explanation as to why its happening and fix for this?

    Thanks.

    <?php
    if (the_author()=="Barbara")
      get_sidebar();
    else {
      include('sidebar-mentors.php'); ?>
    <?php
     }
    ?>
Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi

    use get_the_author instead of the_author. the_author displays on the screen. get_the_author puts the author’s name in a variable. Note it is the display name, so make sure Barbara’s display name is set to Barbara, to work with your example

    Admin / Settings / Users

    Thread Starter nvw

    (@mskopel)

    I knew there had to be a proper way to do this. Thanks for your help.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Using the_author in an If Statement’ is closed to new replies.