Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

share|improve this question

2 Answers 2

up vote 2 down vote accepted

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.

share|improve this answer
    
worked perfectly, thanks –  pete_schuster Feb 18 '11 at 16:07
    
Glad i could help –  Bainternet Feb 18 '11 at 16:14

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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