post

How to Create a WordPress Custom Post Type Template in Genesis

Custom post types can be rather confusing, daunting, intimidating, and frankly difficult. However, with Genesis, custom post types are easy as registering your post type, creating a template, and adding a page that uses the template. While I will assume that you know how to register your custom post type, if you don’t download Brad William’s/WebDevStudios’ Custom Post Type UI Plugin.

To create your page template, you can simply download it here (Custom Post Type Page Template (400)), or follow these instructions. In your favorite text editor, create a new document. Then add the following code:

<?php
/*
 *Template Name: Custom Post Type Template
 */

remove_action('genesis_loop', 'genesis_do_loop');
add_action('genesis_loop', 'custom_do_loop');
function custom_do_loop() {
     global $paged;
    $args = array('post_type' => 'my_post_type');
	//$args = array('post_type' => 'books');

    genesis_custom_loop( $args );
 }
genesis();
?>

Template Name: Custom Post Type Template identifies it as a page template, so when you click Pages > Add New, your new template will appear in the right hand side for Page Templates as whatever you named it. To customize this template, change my_post_type to whatever you named your post type, which should be all lower case with no spaces. The default is ‘post’, which does not pick up your custom post type.

About Travis Smith

As a WordPress Enthusiast, Travis writes about his journey in WordPress trying to help other WordPress travelers and enthusiasts with tutorials, explanations, & demonstrations of the things he learns.

Comments

  1. Gré says:

    Hi Travis
    Thanks for sharing.
    And i you want to add some custom taxonomy on these post type you can add this:

    // Add meta after post
    remove_action(‘genesis_after_post_content’, ‘genesis_post_meta’);
    add_action(‘genesis_after_post_content’,'gncom_ajouter_custom_tax_atelier_lisaa_archives’,30);
    function gncom_ajouter_custom_tax_atelier_lisaa_archives() {
    $gncom_taxo_term = get_the_term_list( $post->ID , ‘les_ateliers’, ‘Les Ateliers: ‘,’, ‘,”);
    echo ” . $gncom_taxo_term . ”;
    }

  2. Hi Travis,

    fantastic post, thanks – it made the job so simple!

    By the way, I also read about the “Genesis Simple Hooks” plugin, so that you can remove the post-type stuff like date, author etc. from displaying – not figured out how to make it post-TYPE specific (that may not be possible) … but this may be of use to your readers (or you)

    Kind regards,
    Tracey

  3. Mel says:

    Great post. I will be trying this one in a little while. I’m new to wordpress/php and jumped right into Genesis.

  4. Sagive says:

    Sorry mate, but this is not a custom post type but just the page that hold (like a category) the post types but what about a custom single.. ?

    • Travis Smith says:

      Correct. This is actually, technically a page template and not a custom post type template. This is actually the almost equivalent to archive-{post_type}.php. This code is best used for the archives display of a custom post type since Genesis handles single custom post types quite well (minus the ability to input extra custom fields), but even then, with the hooks, that’s fairly easy to accomplish. However, I have a series “coming soon” that will walk through everything for Genesis.

Speak Your Mind

*