0

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; ?>
3
  • Just to be clear, are you asking that you want to check if there are terms for a given taxonomy before echo'ing? Jul 5, 2012 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, 2012 at 16:38
  • 1
    That's what I thought, worth being sure ;) @Milo's got the ticket. Jul 5, 2012 at 19:19

1 Answer 1

2

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;
?>
1
  • 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, 2012 at 21:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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