Custom Post Type Template – Archive

I have a custom post type, called ‘job’, and I have the following templates in my theme:

  • single-job.php (works fine, displays single job as expected)
  • archives-job.php (is not recognized?)
  • archives-current.php (also not
    recognized)
  • archives.php (is not
    recognized either?)
  • index.php
    (archives page uses this page)

Here is how I’ve registered my custom content type in functions.php:

add_action( 'init', 'create_jobs' );
function create_jobs() {
  $labels = array(
    'name' => _x('Jobs', 'post type general name'),
    'singular_name' => _x('Job', 'post type singular name'),
    'add_new' => _x('Add New', 'Job'),
    'add_new_item' => __('Add New Job'),
    'edit_item' => __('Edit Job'),
    'new_item' => __('New Job'),
    'view_item' => __('View Job'),
    'search_items' => __('Search Jobs'),
    'not_found' =>  __('No Jobs found'),
    'not_found_in_trash' => __('No Jobs found in Trash'),
    'parent_item_colon' => ''
  );

  $supports = array('title', 'editor', 'custom-fields', 'revisions', 'excerpt');

  register_post_type( 'Job',
    array(
      'labels' => $labels,
      'public' => true,
      'has_archive' => 'current', 
      'supports' => $supports
    )
  );
}

When i go to the url http://mywebsite/wordpress/current/, it displays all of my jobs as expected– but it is not using ANY of the archive templates, and instead uses index.php.

My understanding of the wordpress documentation was that it would look for archives-(special archive for post type name).php, then archives-(post type).php, then archives.php, then index.php… but it just goes straight to index.php?

I did visit the permalinks settings page and clicked save to refresh everything, so I’m not getting 404’s, it’s just not outputting to the correct templates… did I name them incorrectly? Is there a registration setting I missed when I created my custom post type?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

try 'has_archive' => 'true'; and do the permalink reset before testing! and it should be singular archive-job.php rather than archives-job.php


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x