2

I'm trying to display different content depending on the taxonomy that was been selected. For example I have a taxonomy named Type. Inside that taxonomy I have several different children, one is "Photography." I'd like the single of a "Photography" to have a full width instead of it having a sidebar. You can do this in regular Posts by using "if in_category('photography')" but I've spent the past couple hours trying to rig the_terms and the like to function as such.

Thanks in advance for the help.

-Pete

4

Try

function has_type( $type, $_post = null ) {
    if ( empty( $type) )
        return false;

    if ( $_post )
        $_post = get_post( $_post );
    else
        $_post =& $GLOBALS['post'];

    if ( !$_post )
        return false;

    $r = is_object_in_term( $_post->ID, 'type', $type);

    if ( is_wp_error( $r ) )
        return false;

    return $r;
}

Usage:

<?php if ( has_type( 'Photography' ) ) /* do your thing*/ ?>

Hope this helps.

| improve this answer | |
  • Glad i could help – Bainternet Feb 18 '11 at 16:14
7

In WP 3.1, you have the handy has_term() function, found in wp-includes/category-template.php.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.