Site logo

Archived topic

Specific Template for specific custom post type category

3 replies · Started by Anastasia on September 6, 2022

Viewing posts 1–4 of 4

Greetings everyone,

I have created a custom post type (product) and taxonomy (product_category'). For creating the layouts I need for single post and category archive. I used archive.php and single.php which they were renamed to "taxonomy-product_category.php" and "single-product.php" where I've put all my code in order to customize the layout of category archive and single product page.

Since now everything works like a charm.

Although I need for some specific categories of my post type taxonomy to have a complete different layout and content than the default I've made which is the "taxonomy-product_category.php" template file. After some reading I tried to seperate lets say the category "A" from all others using the Custom Taxonomy Hierarchy logic

1) taxonomy-{taxonomy}-{term}.php
2) taxonomy-{taxonomy}.php
3) taxonomy.php
4) archive.php
5) index.php

Unfortunately though none of the above methods seems working since as far as I can understand whatever .php file I create in order to seperate the template for category "A" my "taxonomy-product_category.php" overides it.

Do you have any idea why or any kind of work around?

Hi Fernando,

You got me a little bit confused now. As far as I can see my case in the table of hierarchy you posted is "Custom Taxonomy Archive" which refers to my "taxonomy-product_category.php" file. So as far as I can understand, if I create a file lets say "category_a.php" for the specific category I need it will overide "taxonomy-product_category.php" which is next in priority?

Hi there,

for example in your product_category you add a new term called: shoes
The template name for the shoes category archive would be:

taxonomy-product_category-shoes.php

This archived topic is closed to new replies.