Archive for Custom Post Types with Genesis 2.0

Genesis 2.0 – Archive Settings for Custom Post Types

get the genesis framework
This site runs on the Genesis Framework. It’s the best $59 I ever spent.
(Disclaimer: I’m an affiliate and will retire tomorrow if you buy Genesis through this link)
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.

Pretty cool.

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.

Even cooler.

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.

Within your 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:

  • genesis-cpt-archives-settings

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.

Archive for Custom Post TypesOnce 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 Settings

  • Archive Headline
  • Archive Intro Text

SEO Settings

  • Custom Document Title
  • Meta Description
  • Meta Keywords
  • Robots Meta Tags

Layout Settings

  • Layout Settings
  • Custom Body Class

Here’s a screenshot of the Archive Settings page, ’cause I know we all love screenshots:

Archive-Settings

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. 🙂

Interested to know other juicy technological tidbits coming with Genesis 2.0? One of the lead developers, Gary Jones, has a newsletter you need to sign up for!

85 thoughts on “Genesis 2.0 – Archive Settings for Custom Post Types”

  1. I realize this is quite an old post, but I have a quick troubleshooting question. I’ve set up my custom post type to have the archive settings, but when I click to view the archive, it defaults to the homepage. I also tried viewing one of the posts, and it did the same thing.

    If it helps, I’m using Atmosphere Pro.

    Here’s the code for the CPT:

    ‘//* Add a custom post type
    add_action( ‘init’, ‘cd_post_type’ );
    function cd_post_type() {
    // Speaker custom post type
    register_post_type( ‘speaker’,
    array(
    ‘labels’ => array(
    ‘name’ => __( ‘Speakers’ ),
    ‘singular_name’ => __( ‘Speaker’ ),
    ),
    ‘has_archive’ => true,
    ‘public’ => true,
    ‘show_ui’ => true, // defaults to true so don’t have to include
    ‘show_in_menu’ => true, // defaults to true so don’t have to include
    ‘rewrite’ => array( ‘slug’ => ‘speakers’ ),
    ‘supports’ => array( ‘title’, ‘editor’, ‘genesis-seo’, ‘thumbnail’,’genesis-cpt-archives-settings’, ‘custom-fields’ ),
    )
    );
    }’

    Thanks!

    -Alaina

    1. Hey Alaina,
      Sounds like a permalinks issue. Visit Settings > Permalinks (no need to save anything) and that will flush your rewrite rules. If that doesn’t do the trick, please post this over in the StudioPress forums and leave a link so I can help you over there.

      Cheers,
      Carrie

  2. Nice write up, thanks. I’m trying to come up with a way to display custom post type categories, with the category descriptions, and a link back to the archive. without the posts.

    any suggestions? thanks

  3. thanks for the prompt response. I’ll need to get out my martian decoder ring to find out what to do with that, but nice to know there is some code out there that likely will put this together.

  4. Thanks for the helpful post, Carrie. It was just what I was looking for.

    I was using Toolset Types plugin but after their last upgrade it’s just too pricey for my purposes so I’ve switched to the Custom Post Type UI (CPT UI) plugin. [Good thing I’m at the beginning of my project.]

    Anyway, since it took me a couple of minutes to figure out how to blend your tutorial with the CPT UI plugin, I thought I’d share my solution in case anyone else is trying to figure it out. Once you know how to fit the pieces together, it’s super simple.

    On the “Add New Post Type” screen almost at the very bottom is a text field for “Custom ‘Supports.'” If you just pop in “genesis-seo,genesis-pct-archives-settings” (without the quotes), everything comes up roses.

  5. Hi Carrie,

    Great article, I didn’t know that was possible. I always considered these pages indexes of the post type as they are like the home/posts page is to posts rather than a taxonomy archive.

    Anyway with some further digging I noticed you can use WP-Types plugin still and hook these filters in using the below code. One of your commenters mentioned this was an issue. Thanks, keep up the splendid work.


    //* Adds Genesis Custom Post Type Archive Settings Support to Custom Post Types when using WP-Types Toolset.

    add_filter('wpcf_type', 'add_genesis_post_type_support_cpt', 10, 2);
    function add_genesis_post_type_support_cpt($data, $post_type)
    {
    $arr = array('rests', 'workouts', 'recipes');
    if(!in_array($post_type, $arr)) return $data;
    $data['supports'][] = 'genesis-cpt-archives-settings';
    return $data;
    }

  6. Carrie, this was excellent news for me. I’m newer to Genesis, and was trying to figure how to get a CPT to have it’s archive page. After doing it “old school” last year with a TwentyTwelve theme setup and using two plug-ins and a bunch of hand-coded templates, it’s astounding to see that a simple function would add the CPT and provide archive support automatically. Great post. No wonder you’re near the top in the search results.

Leave a Comment

Your email address will not be published. Required fields are marked *

Carrie Dils uses Accessibility Checker to monitor our website's accessibility.