WordPress.org

Ready to get started?Download WordPress

Forums

Widget Logic
[resolved] Is this code ! is_page( 17 ) || ! is_home() wrong? (12 posts)

  1. swolock
    Member
    Posted 2 years ago #

    This code ! is_page( 17 ) || ! is_home() does not seem to work. I'm using a child theme of twentyten and WP 3.4.1. This code is_single() || is_home() and ! is_page( 17 ) does work. I'm at a loss.

    http://wordpress.org/extend/plugins/widget-logic/

  2. ahmedNaguib
    Member
    Posted 2 years ago #

    I don't think there is a syntax error . Can u tell us what u r trying to achieve ??

  3. swolock
    Member
    Posted 2 years ago #

    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.

  4. ahmedNaguib
    Member
    Posted 2 years ago #

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

  5. jedifunk
    Member
    Posted 2 years ago #

    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?

  6. swolock
    Member
    Posted 2 years ago #

    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...

  7. ahmedNaguib
    Member
    Posted 2 years ago #

    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 :D

  8. swolock
    Member
    Posted 2 years ago #

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

  9. alanft
    Member
    Plugin Author

    Posted 2 years ago #

    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

  10. swolock
    Member
    Posted 1 year ago #

    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.

  11. alanft
    Member
    Plugin Author

    Posted 1 year ago #

    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.

  12. swolock
    Member
    Posted 1 year ago #

    alanft, thank you, I think I get it.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.