Simple Custom Post Type Archives for WordPress
Simple Custom Post Type Archives adds friendly permalink support, template files, and a new conditional for public, non-hierarchical custom post type archives in WordPress 3.0!
WordPress 3.0 opens the door for entirely new content management possibilities with custom post types. As awesome as it is, the first version to implement custom post types is missing a few things. This plug-in patches one of those holes: templates and friendly permalinks that enable “archives” for custom post types, much the like the “blog home” is an archive for all “post” post types.
This plug-in will only add custom post type archives for non-hierarchical (post-like), public custom post types with a “slug” or permalink.
For example, suppose you have a custom post type Movies. WordPress 3.0 takes care of permalinks for individual movie content, for example, http://yourblog.com/movies/casa-blanca/. You might think you could get an archive of all recently added movies (just like the blog home is an archive of all recently added posts) by going to http://yourblog.com/movies/, but this isn’t supported out of the gate. You can do it without permalinks by going to http://yourblog.com/?post_type=movies, but even then, you’re forced to use the index.php template file in your theme. This plug-in enables archive permalinks (yourblog.com/movies), adds two new template files in the hierarchy (i.e. type-movies.php and type.php), and adds a new is_custom_post_type_archive conditional you can use in your theme!
- Adds support for custom post type archive permalinks, i.e. yourblog.com/custom-post-type-name – including paging (/page/2/) and feeds (/feed/)
- Adds two new template files to the hierarchy, type-(custom-post-type-name).php and type.php
- Adds new body classes to custom post type archives, custom-post-type-archive and custom-post-type-(post-type-name)-archive
- Fixes the is_home conditional check on custom post type archives (incorrectly reports true by default)
- Adds a new conditional, is_custom_post_type_archive for use in your themes: can optionally check against a specific post type by passing name of post type
- Fixes the wp_title output on custom post type archives to show the custom type’s label
- Automatically adds feed links for custom post type archives when on a custom archive or singular custom post type if automatic feed links is enabled in your theme
What didn’t make it in this pre-1.0 release:
- New navigation menu widget for easily adding custom post type archives to navigation
Please keep in mind that robust custom post type support is new to 3.0, and although this plug-in was aggressively tested, it’s hard to test it with all possible custom post type setups. For this reason, along with the bullets listed above, I’m considering this a “beta” – in the Google sense – or pre-1.0 release.
You’re welcome to use the code in your own custom post type plug-ins or themes (the code is GPL), but please include attribution to the author.
The changelog is available here.
As always, feedback and suggestions are welcome!
Hi, Great plugin.
I have “products” post type setup with 2 custom taxonomy setup.
I can see products listing when viewing “domain.com/products” but get a 404 on something like “domain.com/products/wetsuits/” and “domain.com/brands/billabong”
any idea on how I can fix this? I included my code.
register_taxonomy(“productcategories”,
array(“products”),
array(“hierarchical” => true,
“label” => “Product Categories”,
“singular_label” => “Product Category”,
“rewrite” => array( ‘slug’ => ‘products’ )));
// Custom taxonomy for Brand
register_taxonomy(‘Brand’,
array(“products”),
array(‘hierarchical’ => false,
“label” => “Brands”,
“singular_label” => “Brand”,
‘query_var’ => true,
‘rewrite’ => true));
The plug-in does not add taxonomy permalinks below the custom post type permalink. I’ll consider adding that feature in the future, but for now, you’d get to the taxonomy archive the same way you would without the plug-in.
I like your plugin, but when I try to use it, the titles of the posts aren’t clickable. Is there a way to fix this?
Is there a way to set the custom post archive as the site’s homepage? Since the archive doesn’t exist as a WordPress page, it does not appear in the list of “Static pages” that one can set as the homepage.
Thanks!
Hi, thanks for this great plugin.
When using it I found that custom post type archive pages didn’t show the blog name in the window title, but something like ‘Custom Post Type | ‘.
After looking through your code I found that in the title filter function ‘scpta_wp_title’, the $title parameter is simply discarded.
To achieve my goal I added the following:
(at the very top)
and then in the
if('right'==..)and
conditional I added
and
as the last line respectively.
Window title now appears as ‘Custom Post Type | My Awesome Blog’.
I have a very weird problem. Two custom post types implemented with this plugin. On one of them, paginate_links() returns NULL, also a language selector from a translation plugin acts up in pagination. On the other one it works perfectly fine. They are both set up the same way. More details at WP support forum: http://wordpress.org/support/topic/paginate_links-returns-null-more
I can’t help a nagging feeling that the plugin may be to blame. Any idea?
Just a mention that may save other folks some time. It seems WP is not always refreshing the permalink structure. If you are running into 404 errors go to Settings/Permalinks and click “Save changes” (don’t have to change anything). Fixed my problems with custom taxonomies not working on a post.
Hi,
Is there an easy way to make a custom search form on top of type.php template, to filter custom post’s list ?
I’ve been trying with:
and
wp_dropdown_categories with a custom taxonomy
with no success. Any suggestion ?
Seem to have found a bug either in this plugin or in the theme. The post featured image shows full size when I use the type archive page.
using the plugin – http://creativecatholiclearning.com/lessons/
by taxonomy category – http://creativecatholiclearning.com/blog/lesson-category/liturgy/
Hi.
Great plugin!
Do you know if it is possible to have the frontpage be the archive page for my custom post type “portfolio”? I would like to display all my portfolio items on the frontpage / landingpage with pagination. I can’t seem to find a solution for this.
Thanks
Vayu
Hi again.
I actually found a solution with the help of these 2 posts:
http://mark.mcwilliams.me/2010/10/wordpress-3-1-introduces-custom-post-type-archives/
http://themeforest.net/forums/thread/pagination-on-wordpress-static-page-set-to-front-page/28120?page=1
I just changed it to this: ‘has_archive’ => ‘/’,
and I used this for pagination:
if ( get_query_var(‘paged’) ) {
$paged = get_query_var(‘paged’);
} elseif ( get_query_var(‘page’) ) {
$paged = get_query_var(‘page’);
} else {
$paged = 1;
}
Cheers
Vayu
Thank you very much. I just assumed it would work and I would have had to completely re-evaluate my project if it wasn’t for this.