1

I've registered a category taxonomy for my custom post type:

function career_create_taxonomy() {

register_taxonomy(
    'career-category',
    'careers',
    array(
        'label' => __( 'Category' ),
        'rewrite' => array( 'slug' => 'career' ),
        'hierarchical' => true,
    )
);
}
add_action( 'init', 'career_create_taxonomy' );

I wish to create a custom page template for this category. Currently my theme is defaulting to archive.php as expected. I see that the wp documentation states that the you can create any of the following:

category-slug.php
category-ID.php
category.php
archive.php
index.php

However I can't use slug, or id because I want it to apply to all categories for this custom post type & any future ones. I could style the archive page as desired however, if any other categories default to archive.php they'll be using this specific template which is no good!

So how can I create a page template for each of my categories assigned only to this specific custom post type?

2

The hierarchy for custom taxonomies is:

taxonomy-$taxonomy-$term.php
taxonomy-$taxonomy.php
taxonomy.php
archive.php
index.php

So, if your taxonomy was called cats, you could target that specific taxonomy with a template file taxonomy-cats.php.

If you wanted to style your tabby cats differently than the rest (because of course you would), then you could use taxonomy-cats-tabby.php.

See wphierarchy.com

  • Hi thanks, i'll give that a go it looks like i got a little confused with the hierarchy. In your example (just so I'm clear) are tabby cats a specific type of cat? – SamXronn Mar 15 '17 at 18:44
  • That's correct. – Nathan Johnson Mar 15 '17 at 18:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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