Codeable info

Monthy Custom Post Type Archives

Posted on by in Blog

Anyone who has played around with WP 3.0+ custom post types knows that they . . . can be a pain at times, particularly when it comes to custom post type archives. Thankfully a few people have taken it upon themselves to develop plugins that care care of many of the grievances of custom post type archives.

Brought to us by rATRIJS, a developer from Scotland, Custom Post Type Archives is a top-notch plugin that fills many of the gaps left by the core WP developers.

This plugin will enable custom post type archives (also yearly, monthly and daily) together with feeds, customizable titles and paging.

This plugin allows you to use a lot of extra functionality that, without the plugin, is only available to regular WordPress posts and pages. These include full post type archives (with pagination), nice URLs, complete custom post type theme template hierarchy (such as ‘post-type-photo.php’), extra conditional checks for custom post type archives, and monthly / yearly post type archives. It is this last feature that I’m going to demonstrate to you.
Monthy Custom Post Type Archives WordPress Plugin

Normally, when using default WordPress posts, we would use a function like wp_get_archives() to create a list of archives sorted by month or year, allowing us to see all posts published within a certain time frame. Unfortunately, this function doesn’t work with custom post types. So that’s where this plugin comes in.

rATRIJS give’s us a function, wp_get_post_type_archives(), that can be used as a replacement for the default WordPress function and will give us a list of archives for a specified post type. We can use it like this:

1
2
3
<ul class="archives">
	<?php wp_get_post_type_archives('events'); ?>
</ul>

This will give us exactly what we’ve been looking for: a monthly or yearly based list of archives.

Note, you will most likely have to be using a pretty permalink structure in order for this to work correctly.

With a plugin like this, it is dramatically easier to fully utilize the great features of custom post types. At the time of writing this, I’ve just used the plugin with a new theme that uses 4 custom post types to their fullest extent.

Link: Monthy Custom Post Type Archives

Comments Closed

Codeable info