WordPress.org

Ready to get started?Download WordPress

Forums

Widget Logic
[resolved] Two different kinds of conditionals for same widget? (3 posts)

  1. khermberg
    Member
    Posted 2 years ago #

    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/

  2. alanft
    Member
    Plugin Author

    Posted 2 years ago #

    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

  3. khermberg
    Member
    Posted 2 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic