WordPress just made it a lot easier to convert your site into a manageable CMS.

On May 1st, WordPress is releasing version 3.0 and with it a lot of cool features. The one I am most excited about is the ability to create custom post types. Because frankly, I am tired of hacking WordPress to perform more like a CMS. With custom post types you will be able to better organize your content and create websites for your non-web-savvy client that they can actually manage.

Back in the old days…

Currently on WordPress 2.X, you are basically limited to pages and posts to display your content. This is perfectly fine if you want to deliver your client something that looks like a blog. But what about posts with multiple content areas and unique layouts? Now you could create custom fields with html and hack template to get a desired effect, but do you really expect clients to handle this when you pass it on? Plus, it will get awfully messy when they have to sort through categories and filters to find their content.

Enter WordPress 3.0 and Custom Posts

In WordPress 3.0 posts are now under you control. Instead of manipulating posts to meet your needs, simply create a new post type (and leave posts where they belong… your blog!). Lets say you have a website that features a list of cars for sale. Instead of hacking posts, you would create a post type called “Cars”. Here you could manipulate the meta boxes to match the needs of that particular post type.

Custom Page in Dashboard

Custom page types live in the sidebar of you dashboard. Pretty neat, eh?

As you can see above, the “Cars” custom post type is nicely incorporated into the dashboard menu. You don’t have to worry about adding a car category or fumbling through posts to find the right content like in WordPress 2.X.  Everything car related can be found in the “Cars” post type, just the way it should be.

But wait there’s more! What customized post type would be complete without customized columns in the edit page? Check it out:

Custom Post Type Columns

With a little code in your functions.php file, you can even customize the layout of the columns on your edit page.

Using Custom Post Types

Creating a custom page is surprisingly, pretty easy in WordPress 3.0. First of all, if you want to try the following code, make sure you have WordPress 3.0 installed (if you can’t wait for the release, pick up a copy at the Nightly Builds). Then go into your template of choice and open up the functions.php file.

This will add a “Cars” custom post type to your dashboard:

register_post_type('cars', array(
 'label' => __('Cars'),
 'singular_label' => __('Cars'),
 'public' => true,
 'show_ui' => true,
 'capability_type' => 'post',
 'hierarchical' => false,
 'rewrite' => false,
 'query_var' => false,
 'supports' => array('title', 'editor', 'custom-fields', 'author')

Using the register_post_type function you create your custom post type with the label of ‘Cars’. This post type supports a title, editor, custom-fields and author. We will use the editor and custom fields in or posts in just a minute, but first lets style the edit page columns.

Add this code to your functions.php just below where you declared your register_post_type function:

add_action("manage_posts_custom_column", "my_custom_columns");
add_filter("manage_edit-cars_columns", "my_cars_columns");

function my_cars_columns($columns)
 $columns = array(
 "cb" => "<input type=\"checkbox\" />",
 "title" => "Car Type",
 "description" => "Description",
 "price" => "Price",
 "availability" => "Availability",
 "comments" => 'Comments'
 return $columns;

function my_custom_columns($column)
 global $post;
 $price = get_post_meta($post->ID, 'price');
 $availability = get_post_meta($post->ID, 'availability');
 if ("ID" == $column) echo $post->ID;
 elseif ("description" == $column) echo $post->post_content;
 elseif ("price" == $column) echo $price[0];
 elseif ("availability" == $column) echo $availability[0];

This just added six columns to your custom edit posts page (checkbox, title, description, price, availability and comments). It fills that content dynamically using information from the post you are about to create. Go into your freshly made ‘Cars’ post type and choose ‘Add New’.

Enter in some content and make sure to use ‘price’ and ‘availability’ as your custom field names (these specific values are called upon in the code you just wrote):

Custom Fields

Make sure to use 'availability' and 'price' as your names if you are following along with the tutorial.

That’s it! You just created your first custom post type. Now that you have your Cars custom post type set up, you can begin styling your templates accordingly. Best of all, when you hand this over to your client, it is much easier for them to update their site. They just need to enter their copy into the editor and custom fields and they are done.

WordPress 3.0 will make it so much easier to use their platform more like a CMS. So, stop wasting time hacking WordPress posts and start using custom post types! If you want to check out more of their new features and updates, check out http://codex.wordpress.org/Version_3.0.

Also, a special thanks to Konstantin for inspiration and Dave Holm for his help refining the code. Be sure to check them out!