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.

This is what I currently have but its not rendering any results...
It was the closest conditional I could think of using to match what Im trying to output but it didnt seem to work. Any ideas?...

NOTE: The taxonomy terms that I am listing in the sidebar need to be visible at all times while viewing custom post type queries, taxonomy archives, and single product/post pages.

   <?php if (is_tax('productcategory')): ?>

        <div id="shop_by_cat">
            <?php
            echo '<ul>';
            $args_list = array(
                'taxonomy' => 'productcategory', 
                'title_li' => __(''),
                'show_count' => false,
                'hierarchical' => true,
                'echo' => '0',
            );   
            echo wp_list_categories($args_list);
            echo '</ul>';
            ?>
        </div>

    <?php else: ?>
    <?php endif; ?>
share|improve this question
    
Just to be clear, are you asking that you want to check if there are terms for a given taxonomy before echo'ing? –  TheDeadMedic Jul 5 '12 at 9:49
    
Yeah, so if I were to extrapolate on that a bit - I'm basically trying to check - if there are terms in "xxx" taxonomy, then output the div wrapper with the list, if no terms exist than do nothing. –  Mr.Brown Jul 5 '12 at 16:38
1  
That's what I thought, worth being sure ;) @Milo's got the ticket. –  TheDeadMedic Jul 5 '12 at 19:19
add comment

1 Answer

up vote 2 down vote accepted

is_tax() returns true on a taxonomy archive page, it has nothing to do with whether terms exist in a taxonomy.

you just need to add a check for anything returned from wp_list_categories before outputting any markup:

<?php
$args_list = array(
    'taxonomy' => 'productcategory', 
    'title_li' => __(''),
    'show_count' => false,
    'hierarchical' => true,
    'echo' => '0',
);
$product_categories = wp_list_categories( $args_list );
if( $product_categories ):
    ?>
    <div id="shop_by_cat">
        <ul>
            <?php echo $product_categories; ?>
        </ul>
    </div>
    <?php
endif;
?>
share|improve this answer
    
Your right @thedeadmedic, i just didnt know how to do a basic if check like that so I defaulted to using conditionals hoping that would work even though the Codex clearly stated what is_tax was for. Thanks for the help guys, and to @Milo for the example. –  Mr.Brown Jul 5 '12 at 21:01
add comment

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.