As I have mentioned before, WordPress 3 has brought about some amazing functionality. Although, the ability to do custom post types has been around for a while now – they seem to have just made it easier to achieve; I’ll try and keep this short and simple.
When Would I use a Custom Post Type?
If you’ve ever had the situation where you customer wants to add something more specific than a standard blog post, say for example a testimonial, and you’ve had to explain to them in a massively long-winded way:
“Just click add new post, add it to the testimonials category, Then choose your custom options, add an image and get the ID, etc…”
It can get very confusing and disheartening for the client.
Using custom post types you can set up a section specifically for testimonials – it will appear in the sidebar, just as Posts does currently, and it will be entitled Testimonials (or whatever you call it).
You can then add testimonials to this section, just as you would add a post to the posts section. Except you will have set it up so that only the fields you need are visible, so in this case – Title, Editor and Featured Image.
Sounds Great! How do I do it?
It’s actually very simple (if you use a plugin, like I will)! Let’s get started:
- Download the Custom Post Type UI plugin and activate it.
- Click the new Custom Post Types option that has now appeared in the left hand sidebar.
- Choose Add New from the sub-menu that appears under the link you just clicked. This is where you will add your new post type!
- Give your post type a Post Type Name. Preferably lowercase and no spaces – this is used in the loop.
- Give it a capitalised Label and a singular form, so for our example: Testimonials and Testimonial. These will be used in the back end when you or the client is adding a testimonial.
- You can give it a description, or just leave it blank.
- This is the best part – click View Advanced Options (NOT View Advanced Label Options).
- The majority of those options will be fine, the bit that is interesting is the check boxes under the Supports section; this is where you choose the fields your Testimonials will have. In our case make sure that only Title, Editor and Post Thumbnails are selected – this is all the user will need.
- Click Create Custom Post Type and take a look in your sidebar, you will now see the new option as pictured earlier!
Using Your New Custom Post Type
Now that your post type has been created you will need to access it in a loop somewhere – in our case we will use query_posts as I mentioned in a previous blog.
Let’s say, for example, that you wanted your latest testimonials to appear on the homepage (index.php in your theme folder, usually). You can use the following snippet of code:
<?php
//The Query
query_posts('posts_per_page=5&post_type=testimonials');
//The Loop
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
..Your content goes here..
<?php endwhile; else: ?>
..If the query parameters are not met, the alternate content goes here..
<?php endif;
//Reset Query
wp_reset_query();
?>
So, this query basically says to show the 5 latest posts from the post type of testimonials. The name testimonials was chosen earlier for the Post Type Name within the plugin settings. Then, after the query has been defined, it will use the standard WordPress loop to display the contents of your post.
Our post has a title, description and thumbnail. So the full code to put on your WordPress page will look something like this:
<?php
//The Query
query_posts('posts_per_page=5&post_type=testimonials');
//The Loop
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php the_title() ?>
<?php the_content() ?>
<?php the_post_thumbnail() ?>
<?php endwhile; else: ?>
..If the query parameters are not met, the alternate content goes here..
<?php endif;
//Reset Query
wp_reset_query();
?>
Be sure to read my earlier post about WordPress thumbnails, although this was for versions of WordPress earlier than 3.0 – it is now called Featured Image. Some of the tips from my post still apply.
As you can see, we have now told the loop to show the title, main content and the thumbnail image. Now everytime you add a testimonial to your testimonial post type, it’ll show on the front page!
If you want the testimonial to have it’s own page when you click it, similar to how the single.php works for normal posts (this is what it will default to, anyway), just duplicate the single.php file and name it testimonials.php – all the posts in your testimonial post type will now default to open using this file, so you can customise it specifically for testimonials.
Conclusion
Using custom post types is great! It can be used for so many things in website design and I’ve yet to use it to its full potential. If any of this has confused you, or you need help, just leave a comment and I’ll try my best to help you.



Excellent use of the new feature added to the wordpress. Using wordpress custom post types we can add new features to the wordpress blogs.
Thanks for this great turorial
Thank you for a great article on how to setup Custom Post Type.
One question you say to have page for testimonials do I have create page for testimonials so that they are posted there.
Hi Gov,
Good question, and one that I probably should have explained! I believe that if you made a custom post type called ‘testimonials’, the default page that it will use would be testmonials.php (you would need to make this page in your theme folder).
However, you can make a page in WordPress called Testimonials, and then assign a custom template to that page. In the custom template, you would need to make a query_posts loop as described above – that should get you on track?
Thanks for this great article – I have a quick question – when I have added this to my homepage – it has replaced all the homepage content and inserted the Custom Post content. How do I get it to display a Custom Post underneath the main homepage content (eg: a Download Now box?)
Thanks.