With the recent launch of WordPress 3.0 there are loads of sweet new features to dig into. Digging into WordPress has a nice summary of many of the new features.
My favourite new features include the custom post types and custom taxonomies (which have been available for a while, but the dashboard management capability has been fully implemented now). I guess those are slightly more advanced features, I think most users may be more excited by backgrounds, header and menus. As such, Matt Hodder already has a great post about enabling WP 3.0 menus, backgrounds and headers in Thesis.
Also, there is an issue with the Thesis Custom File Editor in the dashboard, so if you use that a lot definitely check out the fix for the use_codepress() error.
Today I’m going to cover my favourite new WP 3.0 features.
Custom Taxonomies
Taxonomies are ways to classify posts and custom post types. WordPress has had two taxonomies for a long time: categories and tags. You’ve been able to register custom taxonomies in WordPress for quite a long time and since version 2.7 registering a non-hierarchical taxonomy (similar to tags) has provided a new input box in the post editing screen to assign your custom tag type to posts, but there was no menu item to edit that taxonomy and there was no input support for hierarchical taxonomies (like categories).
Now, registering a new taxonomy provides the input box on post editing pages and a dashboard menu item to edit the whole taxonomy.

Say you were building a website to document the spread of an infectious zombie-creating disease and wanted to profile and categorise individual zombies… You could create a custom post type for zombies (covered below) and assign location and infection taxonomies to make it easy to categorise and query where the zombies were sighted, or originated from, and which strain of the infection they have.
The following code would be posted into functions.php, or custom_functions.php for Thesis.
// === CUSTOM TAXONOMIES === //
function realestate_custom_taxonomies() {
register_taxonomy(
'location', // internal name = machine-readable taxonomy name
'zombie', // object type = post, page, link, or custom post-type
array(
'hierarchical' => true,
'label' => 'Location', // the human-readable taxonomy name
'query_var' => true, // enable taxonomy-specific querying
'rewrite' => array( 'slug' => 'location' ), // pretty permalinks for your taxonomy?
)
);
register_taxonomy(
'infection',
'post',
array(
'hierarchical' => false,
'label' => 'Infection',
'query_var' => true,
'rewrite' => array( 'slug' => 'infection' ),
)
);
}
add_action('init', 'realestate_custom_taxonomies', 0);
The lines in the first registration are commented to explain them a bit, and another post by Justin Tadlock has some more details about custom taxonomies.
Notice that I made the Location taxonomy hierarchical, since I figured I could hone down the location as much as I want, and organise it in a hierarchy of country, state, city, suburb, etc. Also I only enabled it on “zombie” objects, that is, my Zombie post type. However, for the Infections tag I enabled it on posts because I figured I may write posts about the different strains and their evolution. I can enable the Infections taxonomy on Zombie post types within the post type registration below.
Custom Post Types
Custom post types are new in WP 3.0. They are like posts and pages, but are handled separately within the WordPress dashboard and by the regular post query — like pages, they don’t show up on the posts page or in the feed.
When creating custom post types you can call them whatever name you like and you can mix some of the features of posts and pages. For example, you can create a custom post type that is hierarchical (like pages, allowing child pages) and that uses categories, tags or custom taxonomies (like posts already do).
Justin Tadlock has an amazing post with the details of custom post types and how to make them. Refer to that post for all the parameters related to creating custom post types.
In Thesis, creating custom post types is not very different to any other theme. The main difference is that instead of adding the registration code to functions.php you add it to custom_functions.php.
// === CUSTOM POST TYPES === //
function create_my_post_types() {
register_post_type( 'zombie',
array(
'labels' => array(
'name' => __( 'Zombies' ),
'singular_name' => __( 'Zombie' ),
'add_new_item' => 'Add New Zombie',
'edit_item' => 'Edit Zombie',
'new_item' => 'New Zombie',
'search_items' => 'Search Zombies',
'not_found' => 'No zombies found',
'not_found_in_trash' => 'No zombies found in trash',
),
'_builtin' => false,
'public' => true,
'hierarchical' => false,
'taxonomies' => array( 'location', 'infection'),
'supports' => array(
'title',
'editor',
'excerpt',
'custom-fields'
),
'rewrite' => array( 'slug' => 'zombie', 'with_front' => false ),
//'register_meta_box_cb'=>'add_meta_boxes',
)
);
}
add_action( 'init', 'create_my_post_types' );
There are loads more parameters that you could use. I found that these were the ones I needed to create a pretty simple post type with a smooth experience (i.e., all the terms in the admin call the posts “zombie” or “zombies” appropriately, rather than “posts” or “pages”).
Worth noting is that even though the default slug (bit of the URL) will be the label (in this case “zombie”), I had to specifically state it in the registration code, otherwise I got a 404 error on my post. Also, you need to visit the permalink settings page after registering the post type to flush the rewrite rules so the new slugs work (just visit the page, you don’t have to re-save the options).
Thesis SEO & image metadata for custom post types
You might have noticed that the last line of my custom post type registration, //'register_meta_box_cb'=>'add_meta_boxes',, is commented out. Don’t uncomment it because it won’t work! To add meta boxes to the custom post type editing page, you need to provide a callback function and state the function name in the registration code. Thesis doesn’t support this yet, which is why I have custom fields enabled on the editing page. You can still use the Thesis SEO and image fields, but it will be a bit more manual until the callback is supported. I’ve left the line in the code to remind myself to add the callback in when it’s ready and I’ll edit this post to include it when it is.

If you’ve been using the Thesis fields then the keys will probably be available for you in a select box when adding a new custom field. Some of the values you will know what to do with, such as thesis_post_image and thesis_thumb just take an image URL, but if you’re not sure what values to use take a look at the custom fields on one of your older posts already using the Thesis meta to see what should be entered as the value for the field.
More to come
There’s a lot more to WordPress 3.0, but I think this post is long enough. I’m sure I and others will have more exciting things to come!
↓



{ 36 comments… read them below or add one }
Awesome post and thanks for the mention! I’ve been playing around with custom post types and just loving the possibilities.
Really Nice Post!
Lots More Features In WP 3… :) Thanks To Wordpress Team Also …
Thanks Kristarella For Telling How To Add These Features Into Thesis!
Also Matt Has Written A Great Article… Will Help Me A Lot!
May not be everyone’s experience, but if you define custom posts with pretty permalinks, you may need to re-save the permalinks settings panel in WordPress before WordPress will recognize the new slugs. I was getting 404s on my custom post type entries until I did so.
Great article, Kris. Anyone interested in all the possible options and so on, check out the WP Codex. :D
Matt — Thanks, and no prob! I’m all for promoting wach other’s posts rather than rewriting the same tutorial a million times!
Saif — Thanks, hope you have some fun with these customisation possibilities.
Rick — Cheers! Thanks for the link to the codex. I was looking at a page on the codex, but it was not useful enough to link to, I think it was a general description page rather than the function reference.
Wow great blog! I also use thesis and am very impressed with your styling, you make me feel like a newbie.
I like the wordpress 3.0 layout its much more crisper than their last version. I like the fact that they make adding headers easier. Also after reading this post I need to dig into thesis more I think I am missing out on a lot of cool features because of my own ignorance. DOH!
Larry — Thanks :-)
Yes, I quite like the interface changes for WP3 as well. Don’t worry too much about missing features. It’s good to dig deep and get creative with the tools you have, but it’s still a learning process. Everyone has to start at knowing little at first, then knowledge can grow… it’s half the fun!
I have a couple custom taxonomies and I want to use them in the sidebar as I would categories. I want to be able to show a list (preferably in a drop down) and when the user selects a term, Wordpress shows those posts that have that term assigned to them. Just like a category widget does.
Does this widget exist? Is there code I can out in a widget that would do this?
You mentioned that //’register_meta_box_cb’=>’add_meta_boxes’, does not work with Thesis. I needed custom meta boxes for a web app I am writing. This tutorial works shows how to get custom meta boxes working on your site… and this method jives with Thesis too!
http://www.deluxeblogtips.com/2010/05/howto-meta-box-wordpress.html
In fact, the edit page for one of our custom post types is now 100% meta boxes since we don’t need the WYSIWYG for this post type.
Best,
Nick
Mark — I couldn’t find any new functions to automatically create lists or dropdowns for the new taxonomies, but the following function pasted into custom_functions.php will do it (it sticks with the “locations” example, you’ll need to substitute your own values in there.
function location_dropdown() { ?> <li class="widget"> <h3>Browse by Location</h3> <select name="event-dropdown" onchange='document.location.href=this.options[this.selectedIndex].value;'> <option value=""><?php echo attribute_escape(__('Select Location')); ?></option> <?php $locations = get_terms('location','hide_empty=0&hierarchical=0'); foreach ($locations as $location) { $option = '<option value="' . get_bloginfo('url') . '/location/' . $location->slug . '">'; $option .= $location->name; $option .= ' (' . $location->count . ')'; $option .= '</option>'; echo $option; } ?> </select> </li> <?php } add_action('thesis_hook_before_sidebar_1','location_dropdown');See the codex page for get_terms() if you need more parameters in that function.
Nick — Thanks! I’m sure that link will come in handy. When I said the register line didn’t work I was talking specifically about the Thesis SEO & image meta boxes: the ones provided by Thesis. I didn’t mean any meta box that you care to create. Did you find a callback to add the Thesis meta boxes, or was that part of the post just not clear enough?
Oh, I get it now. Upon re-reading your post I see now that you are Specifically referring to Thesis MetaBoxes. Sorry about that!
No, I have not found any way to get Thesis Meta Boxes to load on Custom Post Types. Yet.
Thanks!
Kristarella, thanks for the code!
I’m just glad someone’s started a zombie database!
Hey Kristarella,
I’ve got a simple question for you that has absolutely nothing to do with the topic of this post… which was wonderful by the way, but instead with the features of this post.
You have a fantastic little “Contents” menu in the upper right hand side of this post. I love it and I’ve been searching for a plugin or some other method of accomplishing this with some of my longer posts… but I haven’t found anything. Would you care to share how you made that little “Contents” menu?
Thanks a ton.
Kristarella,
Here’s something I’m struggling with. I have set up a couple custom taxonomies. But I’d like to set up the META Description for each taxonomy archive page. I want to insert the taxonomy term description into the META Description. How do I add the META description for a taxonomy page? I understand the if_tax conditional statement, but what else do I have to do?
I’ve been able to figure out how to create an H1 title and show the term description on-page, and all I need is the to get this META description working to be able to use the taxonomies.
Also, the custom taxonomy archive pages do not have nofollow. This sounds dangerous for duplicate content. I’d like to initially set all taxonomies to no follow while I get set up,, but then would would be a great piece of code would be allow follow IF there is something in the taxonomy term description for that term!
(I wonder if Chris is going to add the meta, nofollow, etc fields to 1.8?)
I mentioned follow/nofollow above. I meant index/noindex.
Richard — The contents menu is implemented via javascript (jQuery) and only requires the subheadings in the post to have IDs in order to link to them. I think I’ll write a post about it, rather than just dumping the code in here. Watch out for that later today.
Mark — As far as I can tell there is no description output on a custom taxonomy page by default in Thesis, so you would just add one via custom_functions.php.
function custom_SEO() { if (is_tax()) : $description = strip_tags(term_description('', get_query_var( 'taxonomy' ))); echo '<meta name="description" content="' . $description . '">'; endif; } add_action('wp_head','custom_SEO',1);It appears that by the default Thesis settings the custom taxonomy pages do have noindex,nofollow. I have the
<meta name="robots" content="noindex,nofollow">tag on my taxonomy test page, and I haven’t changed any of the Thesis settings. I guess if it’s not there with your settings, then you can add it within the function above.I don’t think people realize yet what a powerful feature the custom posts and taxonomies are. This improvement has brought WP to level par feature-wise with other cmss which cater to general (non-blog) sites.
Thanks for the runup of how to implement it.
Thanks once again, Kristarella, for the custom_SEO function. Works great!
Interesting how you have a noindex on your taxonomy pages. I have this
tag. I wonder why the difference? Interesting. But I’ve created a robots.txt file to disallow indexing of my custom taxonomies.
I hope that the next release of Thesis will have all the Page Options fine tuning for custom taxonomies as it has for tags and categories. I’ve asked on the Thesis forum, but trying to get any information about bug fixes (Thesis is horrible with bug fixes), upcoming features, and estimated, even extremely rough, timing of new releases is worse than pulling teeth.
I have a custom post type and some categories within that post type. I then have a page that displays each custom post type by category. When I click to view the single page view of the custom post I get a 404. So the URL should be /customposttype/category/postname, but they links aren’t going there when i click on them, they are going to /customposttype/postname. How do I change this? Also the url that should work, doesn’t. When I put default permalinks on everything is fine.
Chris — Please provide the code you’re using to register the post type and create the page listing post types. If it’s quite long try using Pastebin.com and sending the link. I don’t think I can help without seeing the code.
Thanks for trying to help, your the best! Here is a link to my code.
http://pastebin.com/Lvmzhdn0
Chris — Much of this is all a bit new to everyone, so bear with me. Some issues I see so far is that you said the URL should be “/customposttype/category/postname”, but why? As far as I’ve seen, custom post types URLs are pretty much just “/custom-post-type/custom-post-name”, I haven’t found a way to add the category into the URL. Also, you haven’t enabled categories in your Portfolio post type, so you must mean the URL should contain the genre taxonomy? Unless giving the Portfolio post type “post” capabilities gives it the same taxonomies as posts too, I haven’t explored that option.
The other thing that might be messing up URLs is that you’ve given the genre taxonomy a slug of “portfolio”, but custom post types are given a default query and slug of their label, and “portfolio” is the label of your custom post type. So you should probably change the slug of the genres taxonomy, or specify a slug for portfolio post types. And as I mentioned in the post, I found that if I didn’t specify a slug for custom post types, even though the default slug is supposed to be the label, I got a 404 for the posts.
If you fix up the slugs you should not get 404s anymore, but I don’t know yet if there’s any way to use a taxonomy in the custom post URLs. I wan’t able to figure it out last week and haven’t tried again yet. I’m hoping that if it’s possible Justin Tadlock will write about it soon because he’s been promising more posts on this topic.
Yes, its a taxonomy, sorry. I will try changing the slugs up. As far as the URL, it doesn’t really matter, I was confused. I just want to not get 404s with pretty permalinks, however the URL needs to show up. Thanks for the help, I will let you know how it goes when I try it.
Alright, fixed it. It was the slug problem, and I had a stray “<" in my category.php that I just didnt see, lol. I'm embarrassed now. DOH!
Hi,
I am using the custom post types plugin for now. I have just uploaded a post but it does not appear either under posts or pages which I guess it shouldn’t. But how do I make it appear in the nav menu. I use thesis theme.
Thanks for a great round up Kristarella. I found this on the thesis forums to allow you to add the thesis meta data to custom post types, though I doubt it will be needed when 1.8 final is here. Anyway here it is
add_action(‘admin_init’, ‘thesis_for_custom_post_types’);function thesis_for_custom_post_types() { $post_options = new thesis_post_options; $post_options->meta_boxes(); foreach ($post_options->meta_boxes as $meta_name => $meta_box) { add_meta_box($meta_box['id'], $meta_box['title'], array(‘thesis_post_options’, ‘output_’ . $meta_name . ‘_box’), ‘custom_type_name’, ‘normal’, ‘high’); #wp } add_action(‘save_post’, array(‘thesis_post_options’, ‘save_meta’));}
Marvin — Try using the link category method of adding links to the nav menu (add the link as a blogroll type link to a link category and add that category to the Thesis nav).
David — Thanks for that! Great to know.
No problem I often admire your work from afar. I am enjoying working with these new capabilities and eager to see if 1.8 final includes the same tag and cat support for the taxonomies both in terms of the seo options in the dashboard and the pages they produce. Havent quite nailed the custom templates for custom post types, im as far as tricking the code into thinking its a page type not a post type so its actually possible with thesis but yet to put together a near vanilla template to begin testing with.
One other challenge, im trying to find the supports sub line for adding scribe support for the custom post type edit screen as its available on the standard post and page screens, any thoughts? Keep up the great work.
Have you tried to add more than one wysiwyg? Just curious :p
David — Sorry, I don’t know what would be in Scribe to hook it in to a custom post editor. They might not have built in direct support for 3.0 yet, but if you search the plugin files for
add_metayou might find it.I haven’t really tried to add a single WYSIWYG: I don’t like them very much and prefer the code editor ;-)
Hi Kristarella, I have inspected the plugins code and indeed found the meta and where it says add support for page and post, I created the additional call to support it for the new post type however think I still need to call it from the supports line in the add custom post type.
I shall wait to see what scribe support say, they were quick to respond at first but then havent responded for a few days. I am sure its an issue many are hoping to have addressed.
RE: wysiwyg I am looking into verve meta boxes as I believe one of their options supports adding a meta box with the wp additional controls. Il let you know if I have any luck as it could be a useful feature. It could potentially still be written in without the plugin after seeing how they address this.
Thanks
“Also, you need to visit the permalink settings page after registering the post type to flush the rewrite rules so the new slugs work!”
Good hint! My custom taxonomy slug wasn’t working until I re-visted the permalink page.
Thanks!
Isn’t defining new post type in the theme code just wrong? I’d imagine a plugin providing new post types rather than a theme.
Vincenzo — I wouldn’t say “it’s just wrong”. It makes sense to create your own plugin for it so that you don’t have to worry about it if you change your theme. But it is fairly common practice to pop this stuff in the functions file of your theme, and if you do you’d need to remember to copy over the code if you change themes, but the same goes for plenty of other customisations you might have.
You rock, always! You know that?