Custom post type archive load single-CPT.php
-
Hello!
I would like to make my Parent Custom Post Type to list all its children CPT, and use for each for each of them (parent and children) a different template.
So, I understand that the best way to go is to use for the parent CPT an archive-CTP.php, and for the children a single-CPT.php.
I created both of them, and you can see here the code I used within function.php to create the CPT :<?php function my_custom_post_loi() { $labels = array( 'name' => _x( 'Lois', 'post type general name' ), 'singular_name' => _x( 'Loi', 'post type singular name' ), 'add_new' => _x( 'Ajouter', 'loi' ), 'add_new_item' => __( 'Ajouter une nouvelle loi' ), 'edit_item' => __( 'Editer une loi' ), 'new_item' => __( 'Nouvelle loi' ), 'all_items' => __( 'Toutes les lois' ), 'view_item' => __( 'Voir la loi' ), 'search_items' => __( 'Rechercher une loi' ), 'not_found' => __( 'Aucune loi trouvée' ), 'not_found_in_trash' => __( 'Aucune loi trouvée dans la corbeille' ), 'parent_item_colon' => '', 'menu_name' => 'Lois' ); $args = array( 'labels' => $labels, 'description' => 'Les textes du Droit Malgache', 'public' => true, 'menu_position' => 5, 'supports' => array( 'title', 'editor', 'excerpt' ), 'has_archive' => true, 'publicly_queryable' => true, 'show_ui' => true, 'query_var' => true, 'rewrite' => array('slug' => 'lois', 'with_front' => true), 'capability_type' => 'post', 'hierarchical' => true, ); flush_rewrite_rules( false ); register_post_type( 'lois', $args ); } add_action( 'init', 'my_custom_post_loi' ); ?>
My problem is that when I display a parent CPT, it uses the single-CPT.php instead of the archive-CPT.php. Actually, it doesn’t even use the standard archive.php, only the single-CPT.php.
The child-CPT one is working fine, it uses the single-CTP.php as well.I’m pretty sure i missed (or messed) something, but i don’t know what.
Someone got an idea ?
- The topic ‘Custom post type archive load single-CPT.php’ is closed to new replies.