2

I have several custom post types and we need to create separate archive templates for these. I tried the following advice, but it's still using the default archive template.

In the form of the single-type-template. In the same way that posts are shown on their own page with single.php, custom post types will use single-{posttype}.php if it's available.

So for the above example, you could create a single-acme_product.php file and the product posts would be shown using that template.

In the form of the archive-type-template. In the same way that posts are shown on their own archive with archive.php, custom post types will use archive-{posttype}.php if it's available.

So for the above example, you could create a archive-acme_product.php file and the product posts would be shown using that template.

Any help would be greatly appreciated.

Here is my code

function camps_register_post_type() {
   register_post_type('camps', array(
       'labels' => array(
           'name' => 'Camps & holidays',
           'singular_name' => 'Camps & holidays',
           'add_new' => 'Add New Camps & holidays',
           'edit_item' => 'Edit Camps & holidays',
           'new_item' => 'New Camps & holidays',
           'view_item' => 'View Camps & holidays',
           'search_items' => 'Search Camps & holidays',
           'not_found' => 'No Camps & holidays found',
           'not_found_in_trash' => 'No Camps & holidays found in Trash'
       ),
       'public' => true,
       'has_archive' => true,
       'rewrite' => array("slug" => "camps"), // the slug for permalinks
        'supports' => array('title', 'editor', 'thumbnail')
   ));
}
  • 1
    That advice looks correct. Now please post your code. – s_ha_dum Nov 19 '12 at 14:21
  • Specifically, we need to see your register_post_type() call. – Chip Bennett Nov 19 '12 at 14:22
  • And what, exactly, have you named your template files? – Chip Bennett Nov 19 '12 at 14:54
0

For custom post type with slug camps:

  • Single post template: single-camps.php
  • Archive index template: archive-camps.php
  • This is what we have named it: single-camps.php (which seems to work) but archive-camps.php doesn't – Chris Nov 19 '12 at 14:56
  • What doesn't work? Are you sure the problem is the template file, or might it be the rewrite rules? – Chip Bennett Nov 19 '12 at 15:09
  • Just so I am sure, should the URl to view the archive-camps.php be www.domain.com/camps? – Chris Nov 19 '12 at 15:12
  • Yes: if your CPT slug is camps, the default URI will be example.com/camps. – Chip Bennett Nov 19 '12 at 15:20
  • My apologies, I was looking at the wrong page, duh. That is all working fine now. Thank you so much for your help. – Chris Nov 19 '12 at 15:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.