[Resolved] Specific Template for specific custom post type category

Home Forums Support [Resolved] Specific Template for specific custom post type category

Home Forums Support Specific Template for specific custom post type category

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #2334514
    Anastasia

    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?

    #2334572
    Fernando
    Customer Support

    Hi Anastasia,

    WordPress follows the Template Hierarchy: https://developer.wordpress.org/files/2014/10/Screenshot-2019-01-23-00.20.04.png

    In the image above, WordPress will check if a template exists and moves from left to right.

    So, if you have a template with a higher hierarchy, all other templates wont be used. You’ll need to rename your templates accordingly.

    #2334577
    Anastasia

    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?

    #2334608
    David
    Staff
    Customer Support

    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

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.