How to tart up a WordPress category page

Since I’m running the new podcast from within a category here, I decided it was time to make some long-delayed tweaks to the category archive pages. Some of this information was surprisingly hard to come by, so I thought I’d share it here for fellow WordPress users (note that this only applies to independently hosted sites, not those on WordPress.com).

1. Displaying an RSS button next to the category title

All WordPress categories have their own feeds, but if you want to give your readers the ability to subscribe to them, you have to display them somewhere. I can easily envision someone being only interested in my Nature/Ecology or Photos categories, to the exclusion of everything else. But since I [used to] list my categories in a nifty slide-down menu (click the Browse link in the navigation bar), I couldn’t work the RSS links into a list, which is the usual approach. Why not display them at the head of each category archive page instead?

First I downloaded the standard orange RSS feed icons, uploaded the smaller one (14×14 pixels) to Via Negativa’s media library, and copied and pasted the URL into Notepad. Then after considerable searching, I found the requisite code, added the icon link in the appropriate spot, and placed it one space to the left of the bit that calls up the category title in category-archive.php. Here’s what I ended up with:

<?php
$this_category = get_category($cat);
print '<a href="'.get_category_feed_link($this_category->cat_ID, '').'"><img src="http://yoursite.com/wp-content/ ... /feed-icon-14x14.png"></a>'; ?> <?php single_cat_title() ?>

2. Adding the category description to the first page of the archive

You might’ve noticed that the categories section of the WordPress dashboard (left menu, Posts drop-down) allows you to edit each category to enter a description. These descriptions can even contain links — see for example my Photos category, where I’ve just added links to my photoblog and Flickr page. Most blog themes leave descriptions out, but they’re a great feature, I think. I don’t know why I didn’t do this a long time ago. Here’s the code:

<div class="category-description"><?php if ( $paged < 2 ) { ?>
<?php echo category_description( $category ); ?>
<?php } else { ?>
<?php } ?></div>

The conditional statement restricts it to the first page of the archive. The div definition of course can be anything you want, and one look at my current styling will tell you that I am not someone you want to consult on design.

I’ve barely begun adding descriptions to categories, and probably won’t add descriptions to all of them, but it’s looking like a good way to add additional information or important qualifications. And I just realized that the new descriptions appear as mouse-over text in this theme’s Browse menu, too. Far out.

3. Styling categories

The above tips barely scratch the surface of what’s possible. To create different styles for each different category archive, you have to create a new template file for each category and upload it to your theme. This involves copying and pasting the code from the main category.php into a text editor, then naming the file something like category-7.php, where 7 is the number id of that category. Finding that number is the only tricky part. In the categories section of the dashboard, move your cursor over the category link and look in the status bar at the bottom of your browser. At the end of the string, where it says cat_ID=x — that’s your number.

With new category template files in place, it’s just a matter of defining the CSS styles in the stylesheet and modifying the files accordingly. It’s not something I plan on doing, but I include it here for the sake of completeness. (Please note that if you want individual styles for posts on the index page according to category, that’s an entirely different procedure.)

4. Adding custom sidebar text to categories

This is another thing I’m unlikely to implement here, but it seems really useful for magazines and other not-so-bloggy websites. There are a growing number of plugins to apply this and other CMS functions, but not being a real geek I’m not really qualified to evaluate them, so you should really look elsewhere for authoritative assessments. (Not that you’ll find any: good information on WordPress is hard to find, lost in a sea of search-engine bait.) For what it’s worth, though, we’ve been using the new WP Custom Widget for qarrtsiluni’s first online chapbook (to add publication history notes in the sidebar of pages like this one), and it’s easy to use and still works fine, knock wood. So if I wanted to add custom text to category sidebars, I guess that’s where I’d start. The real way to do this is with conditional tags, but that requires some pretty gnarly coding — it’s not easy copy-and-paste stuff as in the examples above.

Posted in

Dave Bonta (bio) crowd-sources his problems by following his gut, which he shares with 100 trillion of his closest microbial friends — a close-knit, symbiotic community comprising several thousand species of bacteria, fungi, and protozoa. In a similarly collaborative fashion, all of Dave’s writing is available for reuse and creative remix under a Creative Commons Attribution-ShareAlike 3.0 United States License. For attribution in printed material, his name (Dave Bonta) will suffice, but for web use, please link back to the original. Contact him for permission to waive the “share alike” provision (e.g. for use in a conventionally copyrighted work).

8 Comments


  1. Thank you Dave for posting such useful information. Just at the moment it’s like reading Martian, but I’ve found over the past couple of months of blogging that complicated information becomes less daunting with familiarity. At the outset I was struggling, most of the terms being ones I’d never heard. But it’s been a great inspiration to know that you’re there, the font of much WordPress knowledge, and moreover extremely generous with your time and advice.

    Reply

    1. Clive, this information actually isn’t useful to you at all, unless you’re thinking of migrating to a self-hosted set-up, which I don’t necessarily recommend, although it’s not hard to do, because I’m not sure the trade-off of security for independence would be worth it for someone as busy as you. But I have a couple other ideas of WordPress-focused posts that will include advice for people on the hosted version, WordPress.com. I’ve been meaning for some time to start writing occasional WordPress posts, even though I am very much NOT an expert, because a lot of the information that’s out there — and there is quite a lot of it — isn’t terribly helpful or well-written.

      Reply

  2. I’ve been tinkering with my blog’s code lately, and decided to give this a try. I had feed links on my archives page, but not on the category pages. Thanks for the tutorial.

    Reply

  3. In #2 (Adding the category description to the first page of the archive
    ), what page do I put that code on? My theme doesn’t have any archive pages at all in it. Any suggestions? I would love to use the category description on my archive pages. Thanks!!

    Reply

    1. Hi Tim – I’m sorry, I neglected to point out that not all all themes actually have a category archive page. If you don’t have something called category.php in your theme files, I’m afraid you’ll have to create one. Just look at the archive.php file in your theme, which the category archive defaults to, and compare with the category.php in the default theme or Twenty Ten.

      Reply

Leave a Reply