Where’s The Index Page (Or Archive Page) for Custom Post Types In WordPress 3.0?

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");

Cool…easy peasey…

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.

This entry was posted in Tips & Tricks. Bookmark the permalink.

2 Responses to Where’s The Index Page (Or Archive Page) for Custom Post Types In WordPress 3.0?

  1. Dale says:

    Hey “thecitizen”,
    Good post and hits the nail on the head. I’ve been searching for examples of the usage of the highly acclaimed CMS features (especially Custom post types and taxonomies), and yes, it seems that the “features” do indeed feel ” a little hackish for such an acclaimed new feature “. It’s like noone is paying attention to the actual end users of the site. After all, this conetnt has to be accessible. What’s the utility of “Great New CMS features” if they can only be implemented by hacks to the core? That’s just one step away from using plugins.
    In fact, I’ve resorted to looking at plugins to provide an actual admin UI that actually provides an end result of a useful and well organized site. And I all I want to do is create a system to enter Author info (and include bio, the author’s books (and the types/subject matter of thosebooks, links to the author’s website(s) and podcasts or videos related to the author, and then: The big feature: A website page from which the user can find the author by name, by their book(s), by the subject matter of their book(s), etc. I’ve not been able to find a way to add tagging to any item under the custom taxonomy of “books” under a particular author. So thanks for raising this issue.

  2. Tom J Nowell says:

    Delcare ‘has_archive’ => true, when registering your post type in wordpress 3.1, and you should have a custom post archive page.

    To theme this page, the template is archive-posttype.php and will default to using index.php if said template does not exist.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>