Everybody’s got ants in their pants waiting for the arrival of WordPress 3.6 and Genesis 2.0, especially theme developers and others who work crazy customizations on the Genesis Framework.
If you work with custom post types, be ready to GET EXCITED about one new Genesis 2.0 feature in particular… built-in support to create an archive for custom post types, complete with some really cool archive settings.
First, I’ll fill in a little back story on custom post type (CPT) archives and then I’ll show you how to enable CPT archives in your next Genesis theme.
Where do CPT Archives Come From?
Does the stork drop them off? Do a couple of posts have a wild night at the club and create something unexpected and new?
No. Don’t be weird.
Support for a custom post type archive is inherent in WordPress. If you check the template hierarchy in the codex, you’ll see it’s possible to create a template file called archive-$posttype.php (where $posttype is the name of your CPT). A standard loop run on this template would return all posts belonging to that custom post type.
For example, if your CPT was products, you’d create a custom template called archive-products.php. Assuming your CPT slug was also products, you could navigate to www.whateveryourURLis.com/products and see a list of all products.
Create an Archive for Custom Post Types (The Pre-2.0 Way)
There’s a plugin in the repository by Travis Smith called Genesis Custom Post Type Archives. This plugin serves a dual purpose of eliminating the need to create a custom archive template and extending Genesis’ built-in SEO options.
The plugin creates an archive settings interface where you can specify archive intro text along with SEO options such as page title and meta description.
Enable CPT Archive Settings (The Genesis 2.0 Way)
As of Genesis 2.0, you don’t need Travis’ plugin to get the same great feature. With a few extra parameters, you can enable support for archive settings when registering your custom post type.
register_post_type() function, you must include the following:
- ‘has_archive’ => true,
- ‘public’ => true,
- ‘show_ui’ => true, (this defaults to ‘true’ so you don’t technically need to include*)
- ‘show_in_menu’ => true,(this defaults to ‘true’ so you don’t technically need to include*)
Lastly, you must include support for:
Here’s a sample snippet of code used to create a Portfolio custom post type with archive settings enabled:
It’s All in How You Use It
Enabling support for archive settings is a great way to help visitors navigate your site AND a great way to leverage Genesis’ built-in SEO options.
Once you’ve properly registered your CPT, you’ll see the option for Archive Settings is added to your admin menu.
The Archive Settings page includes the following default settings:
- Archive Headline
- Archive Intro Text
- Custom Document Title
- Meta Description
- Meta Keywords
- Robots Meta Tags
- Layout Settings
- Custom Body Class
Here’s a screenshot of the Archive Settings page, ’cause I know we all love screenshots:
That’s ice cold, baby.
Go make beautiful, beautiful CPTs
What cool things will you do with CPTs and Genesis 2.0? The WordPress is your oyster. 🙂