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.
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 . ”;
}
Travis Smith says
Thanks for sharing! I believe you need to declare $post as global.
Tracey Rissik says
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
wpsmith says
Hello Tracey,
Yes, Genesis has several plugins that are specific to its use/purposes. You can see my post about this as well: “Simple” Plugins Developed Specifically for Genesis by the StudioPress/Genesis Community. While I don’t use the Simple Hooks Plugin, it is a VERY good plugin and VERY useful for those starting out. I know the Thesis Hooks Plugin was essential for me in understanding hooks when I first started out.
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.
wpsmith says
Genesis is great! You’ll love it!
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.
Van Wilson says
I am new to Genesis, and this tutorial helped me greatly.
I noticed that the links to download your template code, such as the one on this page (Custom Post Type Page Template (474)), are broken.
Travis Smith says
Thanks! Fixed.
username says
There is nothing about custom post type but custom page type. What a difference!