Until now you had to use a query in your theme or a Plugin to adjust the design or the content according to a specific category. In version 2.9 the template hierarchy gets expanded and you can create with the help of a slug an own template.
Here is an example: some posts with short news – a microblog. Therefore I create a category with this name and use the generated slug.
The presentation of these posts in the category overview should be different. Previously it was necessary to integrate the following query:
if ( is_category('microblog') ) {
// here the output or integration of the stylesheet for category Microblog
}
In WordPress 2.9 it’s sufficient to use the according template category-microblog.php
to use this template, if you are in the category of the slug microblog
. Alternatively you can still use ID, which can be changed but with the name of the slug is the identity unique and easy.
Comments
6 responses to “New Category Templates in WordPress 2.9”
I’ve always used the category-5.php template method to style categories differently, I’ve never had to use queries.
This could already be done with the category ID (category-3.php) – arguably still better since ID check is a bit more efficient and a user might change the slug.
It is allways possiblte to use the id-template. I think, the slug-version is only a other way, better for customer.
For me is the name of the template more intuitive. Sometimes i work local for a client and the ID’s on the local system must be not the same as the ID’s from the live system. So i can edit the category-products.php and i don’t have any trouble with my local system and the live system.
This is also good for theme developers, because you distribute a free or premium theme with a special category template such as “micorblog” and let the user know they have that as an option. The next step would of course, to be able to set “single-microblog.php” But then we might be stepping into custom post types.
I think this is a step up from requiring the ID (easier for the customer and easier to include in a theme). It’s still somewhat limiting because you will require the user of the theme to have a category with the slug of “whatever” to use the template, even if they don’t want one, but still want the template. I’m still glad they added it though.