WordPress.org

Forums

How Can Title Be Blocked on Specific Pages (9 posts)

  1. Storyman
    Member
    Posted 6 years ago #

    I can get the title NOT to post for one page ID, but having trouble on the code for more than one page ID.

    This is the IF code that works for one page: if ((!is_page('35'))

    This is the IF code I used for 2 pages, but it does not work:
    if ((!is_page('35')) || (!is_page('108')))

    What am I doing wrong?

  2. MichaelH
    Member
    Posted 6 years ago #

    Try

    if ((!is_page('35')) && (!is_page('108')))
  3. Storyman
    Member
    Posted 6 years ago #

    Michael,

    Thank you. That works.

    I don't understand why the logic Operator AND is used instead of OR. Shouldn't I be testing against one or the other argument?

  4. MichaelH
    Member
    Posted 6 years ago #

    Welcome to the 'I don't get that' club!

    It's something to do with two NOTs require an AND...but I can't really explain it other than it's a rule to memorize ;)

    Maybe a programmer (or logical person) will stop by and expand....

  5. JeremyVisser
    Member
    Posted 6 years ago #

    Don't worry, I have dreams about PHP, and I get confused around those sorts of things too. Happens to everyone.

  6. MichaelH
    Member
    Posted 6 years ago #

    Well I thought about this over breakfast and I might understand...

    When using OR, only one of the conditions has to be true, and because the first condition is true it doesn't bother to test the 2nd condition.

    So if the page is 108, then the first condition is met (not equal to 35) and it never tests the NOT EQUAL TO 108 portion.

  7. deuced
    Member
    Posted 6 years ago #

    U R Right Michael and may i add this (without being a programmer):

    OR here means:
    Either the first condition is NOT true || the second condition is NOT true

    AND here means:
    If first condition is NOT true && second condition is also NOT true

    Just thoughts before lunch ;)

  8. Storyman
    Member
    Posted 6 years ago #

    Thanks Everyone,

    This has been informative and quite helpful and gives me a better understanding of PHP quirks (probably it is my logic that is quirky and not PHP's).

  9. JeremyVisser
    Member
    Posted 6 years ago #

    It's not a quirk of PHP. It's actually the way pretty much all programming languages (at least all the important ones -- LOLCODE doesn't count) work.

    Once you learn that logic, you can apply it to whatever programming language you choose later on.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.