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.

Building off of this question/answer, I've sucessfully implemented the single view for my custom post types, but I'd also like to offer the same thing for taxonomies. I've looked through the docs and thought that is_taxonomy() would be perfect for filtering out exactly what taxonomy I'm on, but that's deprecated --> and it's replacement, taxonomy_exists(), doesn't necessarily seem like it would fit the bill.

So, first question is, can I do the same thing for taxonomies as single-posts described in the question I referenced? (I'm using his question edit solution currently). And secondly, is is_taxonomy the way to go here?

Really appreciate any insight. Thanks!

Update: Is query the best way to check for the taxonomy?

share|improve this question
1  
possible duplicate of Custom Taxonomy in plugin and template –  Stephen Harris May 3 '12 at 15:01
1  
It's not clear what you want is_taxonomy/taxonomy_exists for. They both (the former depreciated) checked if a taxonomy had been registered. Maybe you are after if the a taxonomy page is being requested? is_tag() –  Stephen Harris May 3 '12 at 15:03
    
Yup - is_tax() was exactly what I was looking for -if you want to re-submit that as an answer I can accept it. Thanks! –  Zach May 3 '12 at 15:15
add comment

1 Answer 1

up vote 0 down vote accepted

This is what I ended up using (for all those interested):

    function override_tax_template($template){
        // is a specific custom taxonomy being shown?
        $taxonomy_array = array('tax1','tax2');
        foreach ($taxonomy_array as $taxonomy_single) {
            if ( is_tax($taxonomy_single) ) {
                if(file_exists(trailingslashit(get_stylesheet_directory()) . 'tax-template-directory/taxonomy-'.$taxonomy_single.'.php')) {
                    $template = trailingslashit(get_stylesheet_directory()) . 'tax-template-directory/taxonomy-'.$taxonomy_single.'.php';
                }
                else {
                    $template = BASE_PLUGIN_DIR . 'includes/tax-template-directory/taxonomy-'.$taxonomy_single.'.php';
                }
                break;
            }
        }
        return $template;
    }
    add_filter('template_include','override_tax_template');

I hooked into template_include to check if there was a file in the active template called taxonomy-YOUR-TAXONOMY-NAME.php and if not, loads the default from your plugin.

share|improve this answer
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.