Ready to get started?Download WordPress


Widget Logic
Widget Logic is_category displaying on homepage (3 posts)

  1. jenniart
    Posted 2 years ago #

    I'm trying to display 2 sets of ads:
    1. Default ads (should appear everywhere except cat 2 & 3)
    2. Ads for category 2 & 3 pages and posts in either cat 2 or 3.

    This is what I have:

    [Default AD CODE]

    Widget Logic:
    !is_category( array( 2, 3 ) ) && !in_category( array( 2, 3 ) )

    [AD CODE for categories 2 & 3]

    Widget Logic:
    is_category( array( 2, 3 ) ) || in_category( array( 2, 3 ) )

    This is what's happening:
    The ads meant for categories 2 & 3 are showing up on the homepage, on the categories 2 & 3 pages, and on posts in categories 2 & 3. It's not supposed to show up on the homepage.

    The other ads meant for the rest of the site do show up on other category pages and posts pages that are not in category 2 or 3. They do not appear on the homepage.

    The weirdest thing about this problem is that sometimes it works... and sometimes it doesn't. Any ideas?

    Thank you.


  2. sometimes it works... and sometimes it doesn't.

    possibly depends on which category the last post in the loop has (?)

    possibly integrate is_home() and/or is_single() into the conditional code.

  3. alanft
    Plugin Author

    Posted 2 years ago #

    yep, you need to combine in_category with is_single, as in_category is true when the first or last (depending on the theme) post in the loop is in the specd category

    It's mentioned in passing in a couple of points in the FAQ



    is_category( array( 2, 3 ) ) || (is_single() && in_category( array( 2, 3 ) ) )

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic