Site icon WP Smith

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 ([download id="5"]), or follow these instructions. In your favorite text editor, create a new document. Then add the following code:
[php]<?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();
?>[/php]
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.