0

I have 2 custom post types that share a taxonomy. The taxonomy template of my taxonomy ( taxonomy-my_tax.php ) will query both custom post types.

Is there a way to have a taxonomy template for each post type ?

2
  • What are you trying to achieve. Taxonomy archive templates doesn't work this way. Oct 28, 2014 at 11:06
  • I'm trying to get an archive template that list the articles form a taxonomy, from a custom post type Oct 28, 2014 at 11:32

1 Answer 1

0

If you want to use one file as a "taxonomy" template, but want to style posts differently by post type, I'd advise using an if statement. I'm not sure how far you're going, but if you're just changing the loop for example, it would look something like this:

Using this question as reference.

<?php while ( have_posts() ) : the_post();

                if( 'blue' == get_post_type() ){
                    //some custom file, custom-blue.php
                    get_template_part( 'content', 'blue' );
                elseif ( 'red' == get_post_type() ){
                    //some custom file, custom-red.php
                    get_template_part( 'content', 'red' );
                } else {
                    //the default loop file, content-format.php
                    get_template_part( 'content', get_post_format() );
                }

endwhile; ?>

You can write an if statement like this to add classes, wrap certain sections in your template and so on - depends on what you need. In my example, it imagines that you have two custom files, custom-red.php and custom-blue.php and if the post type is neither red or blue, then it defaults to it's regular functionality. Hope that helps!

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.