WordPress.org

Support

Support » Plugins and Hacks » Widget Logic » [Plugin: Widget Logic] single posts within a taxonomy?

[Plugin: Widget Logic] single posts within a taxonomy?

  • i’ve seen a few posts in here that touch on related subjects, but never anything that *quite* answers what i’m looking for

    basically, i’d like a widget to show only on posts that are within a taxonomy. NOT posts that aren’t associated with a taxonomy, and NOT the archive page of the taxonomy. i know the code would be SOMEthing like:

    “is_single() && in_tax(MyGroupingHere)”

    but the second half doesn’t really exist, at least for what i’ve seen. any help from the experts…?

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

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

    @alanft

    Try:

    global $post; return is_single() && is_object_in_taxonomy($post, ‘taxonomy x’);

    (from wordpress/wp-includes/taxonomy.php)

    i’ve not tried it, but the comments in that file imply it should work.

    heya alanft – thanks for the response

    that seems to definitely be on the right path!

    when i add that full line to the widget_logic field, it works perfectly on single pages within the taxonomy. however, it appears to also be showing up on single pages NOT within the taxonomy. as if it were only recognizing the first portion (is single)

    did i miss a step…?

    Plugin Author alanft

    @alanft

    i don’t think i understand taxonomies very well – it looks to me like they apply to all posts (of a particular type) or not. but when you say ‘show only on posts that are within a taxonomy’ that doesn’t seem to match up with that. sorry

    much appreciated, alanft, all the same! just to be sure i used your code as you intended, let me detail what I did more accurately. I added the following code to the widget logic field:

    global $post; return is_single() && is_object_in_taxonomy($post, ‘sports’);

    where “sports” is the taxonomy, with groups like “baseball” “football” and “basketball” beneath it. (did i do that correctly, as you intended…?)

    as said, that worked perfectly for any post within the animals taxonomy (all posts under “baseball”, all posts under “football”, etc, etc.). unfortunately, the problem is, the widget still appeared on single pages outside of any taxonomy (e.g.; a post about vacuum cleaners)

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Plugin: Widget Logic] single posts within a taxonomy?’ is closed to new replies.
Skip to toolbar