One thing I’ve discovered through building WordPress sites for various clients, is that the choice given by WordPress between Posts and Pages for content type is often not sufficient.
A content author may regularly publish several different types of content, such as blog posts, news articles, reviews, tutorials, podcasts etc. and so they may feel that standard WordPress Posts are not sufficient to cover all this territory. They want each content type to be separated into its own distinct section, whereas if they all use standard WordPress Posts, they will all be mixed in together.
Post Topic vs. Post Type
One way to separate these content types is to use categories for each content type, and then divide these up again into subcategories.
That works fine, but for me, it’s not a great solution, because categories should describe what the content is about, not what type of content it is. If I write an article about Web Design, the category for that post should be ‘Web Design’ as that is what it’s about. It’s not about ‘Articles’, it is an article.
So my preferred solution is to use WordPress custom post types to separate the different types of content.
To code or not to code?
Now, the hard way to do this involves a lot of custom php coding and editing your theme’s functions.php file, which for the inexperienced can be tricky and time-consuming, with a lot of room for errors to creep in. If you feel confident and you want to do it this way, there are plenty of great tutorials out there which will give you the code you need. Justin Tadlock’s guide to custom post types is a comprehensive explanation.
However, for the sake of simplicity and time-saving, I’m going to explain the easy way, using the Custom Post Type UI plugin. This makes it super-easy to add multiple custom post types through the WordPress admin panel, without having to edit any code.
Once you install and activate the plugin, you will see a new ‘Custom Post Types’ menu at the bottom of your admin menu. In the dropdown, click on ‘Add new’ to add a new custom post type.
Let’s say we are going to be posting movie reviews, so we want to add a ‘Reviews’ post type. On the left of the screen, the bits you need to fill in are the Post Type name and label. I would also provide a singular label. Then click ‘Create custom post type’.
You will now see a new ‘Reviews’ menu item in the admin menu, which lets you add a Review post.
Adding a custom taxonomy
Now we will probably want to create some taxonomies for our new post type. For a standard WordPress Post, the default taxonomies are Categories and Tags, both of which describe the subject matter of the post.
When you create a new post type, you should think about what information you might want to use to ‘categorise’ these posts and create a custom taxonomy for each one. For example, movie reviews might be categorised by genre, actors, language etc.
Let’s create a Genre taxonomy for our Reviews posts. Again, click on ‘Add new’ under the Custom Post Types menu, but this time, we use the form on the right to create a taxonomy. Again, provide a name and labels, but also remember to attach the taxonomy to your custom post type, so that it will be available when you add a new review.
Now you have a Review post type, which has a Genre taxonomy (you can add the other taxonomies in the same way.) You can add a Review in the same way you would add a normal post, but the reviews will be categorised by genre, and crucially, they won’t appear on your posts page.
Getting the new post types to appear on your site
It’s all very well having these fancy new post types, but how do you get them to show up on your site?
You could create a page to act as a ‘Reviews archive page’, then create a page template for that page, and add a custom loop to that page, which pulls in all of your reviews.
However, there is a much simpler way. If you edit your custom post type, and click on ‘Advanced Options’, you will see a dropdown called ‘Has Archive’, which is set to False by default. If you change this to true, then your custom post type will automatically have its own archive page, which works just like the normal posts page. In this case the page would be at yoursite.com/reviews
If you want to customise how this archive page is displayed, you can create a template for it, called archive-reviews.php (for example).
To add this to your navigation using custom menus, you will have to use a custom link, and enter the full URL of the page. This is not best practice, but it’s the only way to do it for now. There is a Custom Post Type Archives in Nav Menus plugin, but it only works in WordPress 3.2 (which isn’t yet available at time of writing).
So now you can have a site with unlimited different types of content, each of which has its own archive and categorisation system. Just another way in which WordPress can be used as a CMS.
Note: You will probably also want to customise the post template for your new custom post type, which you would do by creating a copy of single.php, renaming it e.g. single-review.php, and customising the layout and content to suit your needs.
I’m sure there will be points I’ve overlooked, so please feel free to leave a comment or question below, and we can talk it out!
Update (2 Feb 2012): Yoast has posted about a WordPress plugin that simplifies the process of defining custom post types.