WordPress.org

Support

Support » Plugins and Hacks » [Resolved] [Plugin: Widget Logic] Two different kinds of conditionals for same widget?

[Resolved] [Plugin: Widget Logic] Two different kinds of conditionals for same widget?

  • I am having trouble combining conditional tags for categories and pages.
    I want a widget to show up on all pages except one page and three category archives as well as their individual posts.

    To exclude it from the page, I’ve successfully used:
    !is_page(‘xxx’)

    To exclude it from categories 6-9 and their posts, I’ve successfully used:
    !is_category( array (6, 7, 8, 9)) || (!is_single() && in_category( array (6, 7, 8, 9)))

    However, when I try to combine the two using || the exclusions fail and the widget shows up on every page.

    That is,
    !is_category( array (6, 7, 8, 9)) || (!is_single() && in_category( array (6, 7, 8, 9))) || !is_page(‘xxx’)
    fails, despite each part working individually. I’ve tried the page slug and the page id, but that didn’t help. I’ve also, based on some input from other searches, tried && instead of || to no avail.

    Do you see what I am doing wrong or is it not really possible to combine the two different sorts of conditionals?

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

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author alanft

    @alanft

    I think you should combine them with && with brackets around the second long one

    !is_category( array (6, 7, 8, 9))
    &&
    (!is_category( array (6, 7, 8, 9)) || (!is_single() && in_category( array (6, 7, 8, 9))))

    tho I’m not sure your logic on the 2nd part there is right in the first place. I think it should have the ! next to is_single outside the adjacent bracket.

    !is_category( array (6, 7, 8, 9)) || !(is_single() && in_category( array (6, 7, 8, 9)))

    HTH

    Thanks. I decided to put a conditional into the template to replace the get_sidebar command … it now gets one for page XXX and the other for the rest of the site. Then, your comment about looking more carefully at the brackets and negation got me to this for excluding some of those widgets from the four categories and their posts. I had successfully included a widget in those same places I wanted to exclude others, so I used that code inside !().

    Here is what I used in widget logic for the excluding:
    !(is_category(array (6,7,8,9)) || (is_single() && in_category(array (6,7,8,9))))

    It appears to be working. Thanks for the pointer.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Resolved] [Plugin: Widget Logic] Two different kinds of conditionals for same widget?’ is closed to new replies.