Support » Plugin: Widget Logic » [Plugin: Widget Logic] Can't get widget to show up on appropriate pages

  • I have a widget that I need to show up everywhere EXCEPT for on the blog page, a listing of all posts from the blog category ( and any individual posts in the category “blog.”

    I placed the following code in the WidgetLogic area of the widget (it’s just a text widget), but the widget keeps showing up on individual posts:

    !is_category('blog') || (is_single() && !in_category('blog'))

    To me, this should say that the widget should not show up if the category is blog OR if it’s a single post AND in the category ‘blog’. But it keeps showing up on individual posts that are in the “blog” category (the only category I am using on blog posts).

    What am I doing wrong?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator Ipstenu (Mika Epstein)


    Lead Plugin Wrangler

    Why not just do !is_category('blog')? That should cover it.

    I tried that, too, but it doesn’t work. I read on the Widget Logic FAQ page that in order to make a widget appear both on a category page and a single post within that category, you’d put

    is_category('blog') || (is_single() && in_category('blog'))

    I figured if that makes it appear, then adding ! should make it disappear. But it doesn’t work on the individual posts.

    Moderator Ipstenu (Mika Epstein)


    Lead Plugin Wrangler

    Try category number and not name?

    There’s a slight error in the code is_category('blog') || (is_single() && in_category('blog')

    You need to get rid of the ‘(‘ beside is_single so it looks like:

    is_category('blog') || is_single() && in_category('blog')

    Try that – I don’t know if that will solve your problem but I copy pasted in that code too and didn’t notice the bracket in the wrong place till it spat out an error.

    megmo, the problem is in your logic.

    if ( a || b ) then do x

    will do x if either a is true, or b is true. In this case, !is_category('blog') is true for the index, all categories but ‘blog’, and all single posts. So the second condition is never even tested unless you are on the blog category page.

    You have two choices. You can list all the disallowed possibilities (not index, not blog cat, not single in blog cat):
    !is_home() && !is_category('blog) && !(is_single() && in_category('blog'))

    or you can list the two allowed possibilities:
    ( is_category() && !is_category('blog') ) || ( is_single() && !in_category('blog') )

    Two other interesting bits of logic are:
    !(A and B) == !A or !B
    !(A or B) == !A and !B

    Which means that
    !( is_home() || is_category('blog) || (is_single() && in_category('blog')) )
    is equivalent to the first solution I suggested.

    [Aside to Thorned Rose: the syntax was correct; megmo had a closing paren which got lost when you copied the code.]

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[Plugin: Widget Logic] Can't get widget to show up on appropriate pages’ is closed to new replies.