How2 K2 – Categories
The following article was originally written at Cory’s Weblog. For more articles like this either read Cory’s articles here at DevLounge or visit his personal site.
In this edition of how2 k2, I am going to be discussing categories and some cool things you can do involving them. So, open up your website, get your k2 files at hand, and get ready to further hack-up your blog.
Hiding Categories From The Sidebar
Open your sidebar.php and page-archives.php files and look for the function called list_cats. This is what generates the category list that you see on the default k2 archive pages.
<?php list_cats(0, '', 'name', 'asc', '', 1, 0, 1, 1, 1, 1, 0,'','','','','') ?>
To exclude a certain category, or categories, from appearing anywhere where this list is placed, add the ID number of the category to the last set of quotations. To find the ID number of the category, look in your admin panel under manage > categories. For example, to exclude categories 2 and 9, you would use the following code:
<?php list_cats(0, '', 'name', 'asc', '', 1, 0, 1, 1, 1, 1, 0,'','','','','2, 9') ?>
Notice that you need to separate each category that you are specifying the exclude with a comma.
Also, if you would like to exclude the display of categories in the ELA plugin, just configure it in the options of for the plugin.
Decidedly Bored has a great article discussing how to make a cloud much like the tag cloud for the UTW plugin, but using categories instead.
The category cloud is a creative alternative to the usual, mundane method of displaying categories in a list. It gives the reader a quick visual representation of the relative spread of entries amongst your categories.
If you are interested, check out his article here.
If you are a freak about every little detail of WordPress, then you will find this hack quite cool. After doing a little research about cool things you can do with categories, I came across a great plugin allowing you to make your meta data “talk” to you (for a lack of a better phrase). Basically, instead of displaying categories like “Category 1, Category 2″, it displays them a little nicer such as “Category 1 and Category 2″. This can make the site look a little more user friendly.
All you have to do is download this file, save it with a .php file extension, and drop it into your plugins folder. Once you activate it, it will create a new php fuction called the_nice_category().
Now, just replace the original calling for the category for which it is filed, with the following:
<?php the_nice_category(', "', '" and "'); ?>
Note: This is done in theloop.php.
More information about this plugin can be found at it’s official page.
Well, I think that is enough for this article. I hope you enjoyed the tips and as always, your questions and feedback are always welcome in the comments. Have fun and happy modding!