• Resolved kjetilgf

    (@kjetilgf)


    Hi
    I need some php help here – hopefully it is quite simple, though it takes some words to explain.
    Basically I want a widget to appear on a post which is member of one category (6) but NOT to appear on another post which is ALSO member of an other category (22).
    Possible?

    To explain more thoroughly:
    First of all, I use the Widget Logic plugin that makes it possible to insert php code to separate widgets, so I only need help with the required php code.
    Now,
    On our Italy guide Dolcevita.no we have some map posts that are all members of the Map category (22). But all these map posts are also members of their respective region’s category, like cat 6 for Lombardia. (While the rest of the Lombardia posts are only members of cat 6.)
    To show other Lombardia category-specific widgets I’ve used this code:
    is_category(6) || (is_single() && in_category(6))
    I can easily remove the a widget just from the cat 22 front page by using
    !is_category(22)
    but how can I exclude it also from the posts that are both member of cat 22 AND cat 6 – while it remains on posts only member of cat 6?
    Possible to do some php magic here?
    Here’s the map posts’ front page (just cat 22 – the widget can be excluded with ‘!is_category(22)’) – here’s the Lombardia map post (cat 22 + 6) – and here’s another Lombardia post (just cat 6)
    Grateful for any help
    Kjetil

Viewing 4 replies - 1 through 4 (of 4 total)
  • Try using something like:

    <?php if( !in_category('6') ):?
    [ show widget ]
    <?php endif;?>

    http://codex.wordpress.org/Template_Tags/in_category

    Thread Starter kjetilgf

    (@kjetilgf)

    Thanks a lot for helping!
    But – what would be the required code to use in the Widget Logic field in each widget?
    So far I’ve used

    is_category(9) || (is_single() && in_category(9))

    so somehow I need to add in something like

    !in_category(‘6’)

    but how?
    Thanks again
    Kjetil

    Based on what you wrote above “but how can I exclude it also from the posts that are both member of cat 22 AND cat 6 – while it remains on posts only member of cat 6?”, replace:

    is_category(9) || (is_single() && in_category(9))

    with

    in_category('22') && in_category('6')

    This will show only if they’re in both cat 22 and cat 6.

    Thread Starter kjetilgf

    (@kjetilgf)

    Here’s the answer – with the help from the author:
    ‘is_category(9) || (is_single() && in_category(9) && !in_category(22))’
    A big thank you also to esmi and mtw28 for trying – I believe my description was a bit tricky
    :o)

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Exclude widget from category – possible?’ is closed to new replies.