Forums

If, elseif...is there an "or" function? (5 posts)

  1. logipundit
    Member
    Posted 4 years ago #

    This is simply confusing me to death.

    Is there not an "or" function in the php code? If I'm using conditional tags, for example:

    <?php } elseif (is_author('admin')) { ?>
    Blah blah blah

    <?php } elseif (is_author('18')) { ?>
    blahdy blah blahdy blah

    What if I want three different pages, a couple of author archives, and three different categories all to produce the same result? Do I have to input that desired result 8 different times?

    I feel like it's right in front of me, but I'm just missing something.

    I hope the question is clear; if not, I can cite a few more examples.

    Thanks a bunch if you can help.

  2. Hafiz Rahman
    Member
    Posted 4 years ago #

    Hi,

    you can use either the keyword "||" or "or" to do logical expression. Like:

    <?php if( is_author('18')|| is_author('admin') ) { ?>

    Here's more about logical operator in PHP.

  3. logipundit
    Member
    Posted 4 years ago #

    So the logical expression for "or" is..."or"?

    LOL...

    Dude you're such a lifesaver; I knew that had to be it. I just had the parentheses closed in the wrong places...

    I was doing:

    <?php if( is_author('18'))|| (is_author('admin') ) { ?>

    instead.

    So there you go...it works perfectly now, and I've saved tons of lines of code.

    Thanks again.

  4. logipundit
    Member
    Posted 4 years ago #

    or rather I was using "or" instead of "||" but either way.

    Make it a great night.

  5. Otto
    Tech Ninja
    Posted 4 years ago #

Topic Closed

This topic has been closed to new replies.

About this Topic