WordPress.org

Ready to get started?Download WordPress

Forums

Widget Logic
single posts within a taxonomy? (5 posts)

  1. drkknght
    Member
    Posted 2 years ago #

    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/

  2. alanft
    Member
    Plugin Author

    Posted 2 years ago #

    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.

  3. drkknght
    Member
    Posted 2 years ago #

    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...?

  4. alanft
    Member
    Plugin Author

    Posted 2 years ago #

    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

  5. drkknght
    Member
    Posted 2 years ago #

    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)

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic