How can i display all archives of different post type in different template ?

Thank you for your reply, but I think you did not understand my question. I already created archive-project.php and archive-news.php . But when i am going to category archive of these custom post type it using archive.php template. I want to use archive-project.php for category archive of ‘project’ post type.

  • This reply was modified 2 days, 18 hours ago by smsaikat.

You are using a child theme for this, right? Did you add code in your function file as the instructions said?

“First thing you need to make sure is that your custom post type has archive enabled in the code. To do this, you need to go to your custom post type code (can be found in your theme’s functions.php file or site-specific plugin file). You need to make sure that you have has_archive argument set to be true.”

I am developing this theme and already ‘has_archive’ => true, I want to display category archive for a specific post type in a specific archive-{post-type}.php page. For example, I have a cpt named ‘project’ and i have a category named ‘python-projects’. All python projects are in this category. When i am viewing this ‘python-projects’ category by using this link http://localhost/wordpress/category/python-projects/ all projects are displaying in archive.php , But i want to display this category archive in archive-project.php
Currently archive-project.php displaying default archive of cpt ‘project’, I want to display both category archive and default archive of cpt ‘project’ in archive-project.php

An example code would look like this:

add_action( ‘init’, ‘create_post_type’ );
function create_post_type() {
register_post_type( ‘deals’,
array(
‘labels’ => array(
‘name’ => __( ‘Deals’ ),
‘singular_name’ => __( ‘Deal’ )
),
‘public’ => true,
‘has_archive’ => true,
)
);
}

Note: Deal and Deals would be your customize post type name.

Can you paste a copy of your functions.php code related to this?

Category archives would never use a CPT archive template. I think you’ve seen this page, but maybe you need to review it again: https://developer.wordpress.org/themes/basics/template-hierarchy/

It would be possible to force a specific template file be used for any given request through the “template_include” filter. But if you intend your theme for inclusion into the WP theme repository, forcing template usage this way might not be allowed. It’s up to the theme review team to decide what is allowed or not.

Ok, Thank you so much everyone. 🧡



Source link