Viewing 11 replies - 1 through 11 (of 11 total)
  • I don’t think there is a syntax error . Can u tell us what u r trying to achieve ??

    Thread Starter swolock

    (@swolock)

    I want to hide a text widget on page 17 and also on the static page assigned to showing the blog posts (as in Settings > Reading > Front page displays). It seems like when I add the or || or the not ! it breaks.

    Use && instead of || , so it becomes :
    !is_page( 17 ) && !is_home()

    Why does && work that way. My limited understanding of PHP operators is that || is for OR, whereas && is for AND.

    which would mean that !is_page(17) && !is_front_page() would be saying if the page is not 17 AND not front page, whereas !is_page(17) || !is_front_page() says if not 17 OR not not front page.

    in this case OR would seem to be the proper use. am i crazy?

    Thread Starter swolock

    (@swolock)

    jedifunk…

    I’m 99% sure you are correct, && means and, || means or. In any case I was not able to get || to work with a ! statement. I gave up and went another route. I also tried it on another WP installation, no active plugins except Widget Logic and essentially a fresh install but had the same problem. I really like Widget Logic but I just could not get || to work with !. C’est la vie…

    it is just a logical operation
    || returns true if one of the two sides is true
    so here is a scenario for you to understand it :

    if (x!=1 || x != 3)

    suppose x = 3
    then 3 != 1 || 3 != 3
    true || false
    so the result is true

    I hope this made it clear ??

    Thread Starter swolock

    (@swolock)

    Thanks ahmedNaguib. I understand the difference between || and &&. It just wasn’t working with Widget Logic. I gave up trying to figure out why.

    if you want a widget to appear when it is true that the current page is both not case X AND not case Y at the same time you have to use AND

    ! caseX && ! caseY

    Thread Starter swolock

    (@swolock)

    Thanks all. I understand about both true. What isn’t working is a not condition OR a different not condition. In other words, don’t show the widget on page 17 OR on any post, but show it everywhere else, ie. ! is_page( 17 ) || ! is_home(). Another example might be don’t show the widget on the page ‘contact’ and don’t show it on the front page but do show it everywhere else, ie. ! is_page( ‘contact’) || ! is_front_page(). That’s the kind of thing that hasn’t been working with Widget Logic.

    you have your idea of AND and OR backwards

    !is_page(17) || !is_home()

    will show if the current showing webpage is not page 17, or if it’s not the home page. This is *always* going to be true if page 17 is not the home page, so either one of those statements (A OR B) will be true.

    What you want is AND instead of OR…

    !is_page(17) && !is_home()

    which will only be true when you are not showing page 17 AND you are not showing the home page – ie it doesn’t show on just those specific pages, and does show elsewhere.

    Thread Starter swolock

    (@swolock)

    alanft, thank you, I think I get it.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘[Plugin: Widget Logic] Is this code ! is_page( 17 ) || ! is_home() wrong?’ is closed to new replies.