0

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?

3
  • 1
    possible duplicate of Custom Taxonomy in plugin and template Commented May 3, 2012 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() Commented May 3, 2012 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
    Commented May 3, 2012 at 15:15

1 Answer 1

2

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.

Your Answer

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

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