Archived topic
Custom Taxonomy & Custom Post Type Template creation
6 replies · Started by Anastasia on July 19, 2022
Greetigns everyone,
I've made a custom post type and taxonomy which I've already registered inside my child theme's functions.php.
I'd like to know if there is a guidline or a detailed documentation (something I searched for already but didn't find anything in detail so far) for creating my own templates for taxonomy archive template and single custom post type custom template.
Which files I need to use and overide them inside my child theme folder?
Do I need to create a folder "Templates" and include in there the templates ?
Hi Anastasia,
Here’s an article you may refer to regarding this: https://docs.generatepress.com/article/setting-up-a-simple-custom-post-type/
Hope this helps!
Hello Fernando.
This was the post I was reading but unfortunately it's not working. I think that I miss something.
Steps I did:
1) I copied archive.php into my child theme folder and renamed it as archive-products.php
2) I copied content.php into my child theme folder and renamed it as content-products.php
3) Inside archive-products.php in line 47 I changed generate_do_template_part( 'archive' ); into get_template_part( 'content', 'products' );
Alhough when I try to comment out some lines inside content-products.php to check if anything changes in the content I'm seeing on the frontend nothing changes.
I'm trying to create two new layouts (templates) for my custom taxonomy category archive and custom taxonomy single post
I've just followed the guide you sent me for the single and content single and it works as far as I can see.
My problem though for archive.php for my custom taxonomy still exists. I've made a php file named taxonomy-product_category.php and I copied everything from archive.php inside of it. If I commend the loop I get no results in the archive page of my custom taxonomy. That tells me that the file works properly. Though I can find which is the constructor of the html template which echos inside the loop.
I see.
To clarify, when you created your CPT, did you set has_archive to true?: https://developer.wordpress.org/reference/functions/register_post_type/#has_archive
To be sure, can you try using a plugin like this: https://wordpress.org/plugins/show-current-template/ and check if the template used in your CPT archive is the template you added.
Kindly let us know.
Yes I did set has_archive to true .
For now I created a file named taxonomy-product_category.php and I'll start coding from blank in order to create the layout I need. I kept only the hooks for header and footer. Seems it's working.
I see. Glad it's working now. You’re welcome Anastasia!