Omer asked this question recently which you may find useful if you are in the same situation.
I’m using the Parallax Pro child theme and have created a new custom post type called Podcasts. I’d like to be able to create a page at http://www.example.com/podcast that shows me a summary of all podcast posts. This would be exactly how http://www.example.com/blog shows me a summary of my blog posts.
How To Name Your Template File
The WordPress Template Hierarchy dictates how WordPress looks for archives and templates so you need to use it correctly.
For custom post types, this is what the WordPress.org Codex states:
So clearly in this case the name for the file should be archive-podcasts.php otherwise the standard archive.php file will be used when no archive-cpt.php has been added and found by WordPress.
Here’s some sample code which works with Genesis that you can use in a new file for your CPT archive page.
Code Installation – Beginners Guide
- Create a new file names archive-podcasts.php using a code editor like Notepad++
- Copy all the PHP using the view raw link in the Gist and paste it into the file.
- Save the file and upload it to the root directory of your child themes folder.
- Add a new custom link to your menu example.com/podcasts which will display your podcasts CPT archive
How Did You Create Your Custom Post Type?
An important point which needs to be clarified here is how did Omer create his custom post type?
The reason this point is important is because plugins create CPT’s differently than code. If you use this code to create a custom post type that works with any theme, it includes a parameter which supports CPT archives.
'has_archive' => true,
The above setting ( parameter ) in the CPT code tells WordPress to display a standard archive page when the URL matches the name of the custom post type, http://example.com/podcasts so there’s no real need to create your own custom CPT archive template unless you want to make the page look different which is what the code in the Gist above does.
If the above parameter was false, http://example.com/podcasts would return a 404 page mot found error even if you included a custom archive-podcasts.php file in your child themes root directory.
Note: When adding, removing or modifying custom post type code, you may need to flush the re-write rules in your .htaccess file which you can do simply by re-saving your Permalink settings.
The Bottom Line
If you’re happy with the way your standard archives look and function, you don’t need to create any new files, simply make sure your CPT code includes support for archives.
If you want a custom job, try the code in the Gist and modify it to your liking.