• I’m new to post types and taxonomies so I’m hoping I can explain this clearly.

    I am using post_types to categorize my products. I currently have 2 post types. One titled cars the other titled trucks. Each have their own categories that I’ve created with taxonomies. So for example Cars has 3 taxonomy categories which are red, yellow and blue. The truck post type also has 3 category taxonomies of red, yellow and blue. When I go to view a listing of all the blue trucks that I’ve posted, I see this in the URL bar https://www.mywebsite.com/categories-trucks/blue . This page is using the default archives.php page. So my question is how do I go about adding a custom archives template with the information that I’ve provided. I want the template to look exactly the same for trucks and cars but I want it to look different from my regular blog post archives. I’ve viewed the Template Hierarchy at https://codex.www.ads-software.com/Template_Hierarchy but it did’t make a lot of sense with how I’ve setup my product listings. This is the code I’m using:

    function create_post_type() {
        register_post_type( ‘trucks’,
            array(
                'labels' => array(
                    'name' => __( ‘Trucks’ ),
                    'singular_name' => __( ‘Trucks’ ),
    				'all_items' => __( 'All Trucks’ ),
    				'supports' => array('title','editor','thumbnail')
    
                ),
            'public' => true,
            'menu_position' => 5,
            'rewrite' => array('slug' => ‘trucks’)
            )
        );
    
    	    register_post_type( 'cars',
            array(
                'labels' => array(
                    'name' => __( ‘Cars’ ),
                    'singular_name' => __( ‘Cars’ ),
    				'all_items' => __( 'All Cars’ ),
    				'supports' => array('title','editor','thumbnail')
    
                ),
            'public' => true,
            'menu_position' => 6,
            'rewrite' => array('slug' => ‘cars’)
            )
        );
    
         register_taxonomy( 'categories-trucks’, ’trucks’, array( 'hierarchical' => true, 'label' => 'Categories', 'query_var' => true, 'rewrite' => true ) );
    
         register_taxonomy( 'categories-cars’, ‘cars’, array( 'hierarchical' => true, 'label' => 'Categories', 'query_var' => true, 'rewrite' => true ) );
    
    }
    
    add_action( 'init', 'create_post_type' );
  • The topic ‘How to create archive template for post type categories’ is closed to new replies.