WordPress 3.0 offers the exciting new world of custom post types, giving you the ability to manage and present content with fine-grained control. Creating custom post types is the easy part, but how do you get them to show up in your theme? This tutorial will walk you through this process from start to finish. You’ll be able to incorporate custom post types into your WordPress theme in three easy steps.
Step 1: Create a Custom Post Type
There are basically two ways to create custom post types: add them with your theme’s functions.php file or create them using the help of a plugin, such as Easy Post Types.
For this example, we’ll create a custom post type for recipes. If you wanted to add the post type through your functions file instead of installing another plugin on your site, here is what you would include:
// Creates Recipes post type register_post_type('recipes', array( 'label' => 'Recipes', 'public' => true, 'show_ui' => true, 'capability_type' => 'post', 'hierarchical' => false, 'rewrite' => array('slug' => 'recipes'), 'query_var' => true, 'supports' => array( 'title', 'editor', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'thumbnail', 'author', 'page-attributes',) ) );
Most of the items above are fairly self-explanatory. You will alter the post type, label and rewrite with the type of post you want to create.
If you want more information about registering custom post types, check out the WordPress codex.
After you save your functions file, you should see your new custom post type in the dashboard menu, as shown here. Now you can start adding new recipe posts.
Step 2: Add Your Post Type to a Custom Page Template
Adding your newly created custom post type to its own page is easier than you think. Make a duplicate of your theme’s page.php file. Add this to the top to let WordPress know that it is custom page:
<?php /** * Template Name: Recipes Page * * Selectable from a dropdown menu on the edit page screen. */ ?>
Then you will add this bit right before the loop (above the if ( have_posts() section):
<?php query_posts( 'post_type=recipes'); ?>
Step 3: Create a New Page For Your Custom Post Type
Create a page as usual through the WordPress dashboard. Give it a title and make sure to assign the “recipes” template to your page. Click “Publish” and now you should see a full page of your recipe posts.
If you want to have thumbnails included, make sure to enable post thumbnails for your theme and add this tag into your custom page template:
<?php the_post_thumbnail(); ?>
That’s everything from start to finish. There’s a lot more information to explore in the codex and other tutorials for pimping out your custom post types even further. Now that you have the basic idea, you can customize from there and start managing your content with greater flexibility.





Wonderful! I didn’t know about this feature. This is going to ease so many thing on the plugin I have been working on.
Good!
Thanks so much for the tutorial. This is exactly what I needed.
I’m wondering… if I display posts by post type, how do I display the categories of each of the custom posts? I was told that I cannot use the in this instance, so I’m wondering what exactly I should use.
If anybody could tell me, that would be greatly appreciated!
Thanks.
Now with those custom post types and other “bits of content” that don’t necessarily need to be organized by date/chronologically, what approach you suggest taking for letting the editor/admin of the site SORT their order??
Hello, Nice tip! I try it and it works successfully!
But I have some questions.
How can I do to assign a Category to my recipes posts?
Is it possible to make 2 recipes pages?
Thank you very much!
Thank you so much for the tip! I’ve been trying this for a while and now it works so beautifully!
Can’t get the template dropdown to display?
- Have copied the page.php template and provided a template name.
Not sure what I’m doing wrong?
Simon – did you add the bit at the top of your page template to let WordPress know it’s a custom template? (step 2)
Hi Sarah,
Thanks for responding so soon. Yes, I added exactly as described. Copied the page.php file, (twentyten theme). Added the Template Name above the get_header(); code and added the query_posts for post type function call above the loop.
I’m somewhat at a loss, if it really is that easy?
- I just don’t see the template dropdown when adding / editing a post?
Are you running 3.0 or 3.0.1? – am wondering if there’s a bug fix that’s relevant in the maintenance release. I’ll upgrade now anyway to rule it out..
Cheers.
Simon, you won’t see it on the post edit screen. The template drop down is on the page edit screen where you will name the page “Recipes”, for example, and then select the Recipe template. Then you never touch that page again. You’ll create your recipes post within the “Recipes” menu that you see in your dashboard, as shown in the thumbnail.
Aah, sorry – note to self, read the article properly!!
Fantastic, works perfectly and I appreciate your help Sarah.
Thanks!
-Simon.
Excellent arcticle!!!
I’d set up a custom post type by following Justin Tadlocks guide but for the life of me couldn’t work out how to get it to display in page.
One question…I’m using the TwentyTen theme and currently the page shows a header image then the menu and then goes straight into listing the posts.
Can I add a sentence between the menu and the posts? if so, how?
Nice..it really works…but i want to know that how to add custom DATABASE FIELDS(COLUMNS) to a CUSTOM POST and then show it in the page???
Pingback: The Easiest Way to Get Custom Post Type Archives for WordPress 3.0 - WordPress, Multisite and BuddyPress plugins, themes, news and help – WPMU.org
Pingback: The Easiest Way to Get Custom Post Type Archives for WordPress 3.0 - WordPress, Multisite and BuddyPress plugins, themes, news and help – WPMU.org
Hi,
Thanx
Great tutoriall! i´m really intrested in styling my custom post,
do you know any good and simple tutorial on how to customize?
Cheers
What about pagination?
I tried inserting next_posts_link() and previous_posts_link() and got 404 errors when I clicked on either.
Using a custom template is easier than that. After you copy the page.php or single.php, rename it using this convention:
single-custom_post_type_name.php
So as your example says your custom post type is recipes then your template would be named:
single-recipes.php
Then you don’t need to select it from the page template meta box when you create a new one.
This article saved me. I am building a video player for a site using custom post types, this is an easy way to create and display my videos much like vimeo without having to install some crazy video player wordpress theme. I love it.
Wonderful article Sarah, thank you. I’m fairly code-savvy, and Custom Post Types should be easy, but the number of lacklustre plugins and half-baked tutorials i’ve trawled through has been soul-destroying. This is the first no-nonsense, helpful tutorial i’ve come across that tells you how to create custom post types and *how to actually display them* :-O I still need to modify it to suit my purposes, but you’ve given me the basics to build on. Thanks again.
This was exactly what I was looking for, thank you so much.
Pingback: Más sobre taxonomías y tipos de contenido personalizados: artículos, tutoriales, presentaciones | La Bitácora del Tigre
i dont understand.. should i leave the loop tags aka “if(have_posts)”.. after this tag “query_posts( ‘post_type=recipes’)”…
How about showing a working example inside the loop ?
Awesome! Thank you very much. Lots of stuff on creating custom post types but very little on displaying. This was super helpful. Thanks again. – Jeff
Hi Sarah,
I am using Create a Custom Post Type code. It is working fine.
But i want to add some more filed for example statdate,enddate, and image1 , image2 for multiple images. so how i can do it with it. Please help me asap.
Thanks
Hemant
Thank you so much! Really great article!