WordPress is probably my goto CMS platform (yes I said CMS) for client work in my day-to-day gig (full-time web designer/developer). Needless to say, since I use it so much, I’m stoked that the feature-packed WordPress 3.0 is upon us.
Unfortunately, I’ve been so busy that up until recently I haven’t been able to really follow along the nightly build/beta releases, but I have been salivating for custom post types for a long, long time. So much so, that I’ve used Expression Engine (with far better implementation of custom posts/custom fields) quite a bit as an alternative for clients.
Alas WordPress 3.0 is right around the corner and I’ve toyed around with the vaunted custom post type feature a bit, and although not nearly as polished as the Expression Engine implementation, it is a very powerful step forward for the WordPress platform. Aside from the fact that there’s no real admin UI as of yet (*cough* Expression Engine *cough*) the first thing that really raised an eyebrow was figuring out where exactly to put these new, peculiar post types.
It was apparent after scouring a few blogs, that once setting up the custom post type in the functions.php file, that I could modify any loop by simply adding a parameter to the WP Query ie…
global $wp_query; $wp_query = new WP_Query("post_type=your_post_type&posts_per_page=5");
BUT…what wasn’t apparent was how to create a landing page just for a specific post type, one that was accessible by a unique URL (ie yourblog.com/your_post_type).
Before the big jump to WordPress 3.0 I would use categories primarily for the major sections of the clients’ sites, and of course WP has always had an easy to understand template hierarchy that lets you create unique templates for different categories, and lets those categories become accessible by very pretty permalinks, if so desired.
I really didn’t see anything in the currently sparse 3.0 documentation that explained how to do something similar for custom post types. Hmm…
So I did a little more scouring and I found out that I’m not the only one who found this implementation (or should I say “lack of implementation”) a little confusing. Over on Justin Tadlock’s blog, I found someone raise similar concerns, and Justin’s response to it. http://justintadlock.com/archives/2010/04/29/custom-post-types-in-wordpress#comment-188177
Interestingly enough, not only did that someone find the custom post type implementation lacking…they actually wrote a helper class to try and make up for it. (Wow…I was just content with complaining about it…so kudos to him). To learn more about that helper class see: Smarter Custom Post Types in WordPress 3.0
Going back to the original discussion at Justin Tadlock’s blog, the alternative solution suggested by Justin himself, was to drop the modified custom post type loop on a custom page template. This actually was the way I started doing it initially, but it felt a little hackish for such an acclaimed new feature. (But apparently since there isn’t an unhackish way of doing it yet, I’m adopting this method for the time being.)
Also interestingly, there’s some debate as to whether pagination and site feeds will work on this new “custom post type on a custom page template landing page” (that’s a mouthful). Honestly I haven’t dug into it to much yet, but I’ll be sure to update this post if and when I find out more about that.
My take away from this…the custom post types in WordPress 3.0, although great, are still a work in progress.
UPDATE: I’ve found a couple more solutions both of which seem to take the basic concept of creating your own archive/landing template for a post-type and making the URL map to the correct place through hacking/modifying of WP’s rewrite rules. Here is a cool write up about it from Ballyhoo Blog , and another post from kovshenin.com where the author briefly hints at using the “$wp_rewrite->add_permastruct()” method to achieve the desired effect.