- Subscribing to Categories
- The Challenge
- The Code
- Try It for Yourself
Okay, so this was my challenge: Create some WordPress code to display a clickable RSS feed link and category name link for each category assigned to a post. Insert that code in my post.php file so that it appears in place of the usual category listing for a post. And do it in such a way that it fits in with the site’s existing design.
As usual, I started thinking about this problem a few days before I actually started coding it. (I like to let my brain work on things a while.) Then I sat down at my computer with the template files for the companion web site for my book WordPress 2: Visual QuickStart Guide (WordPress VQS). That’s the smallest and simplest of the sites I manage—but more importantly, it’s the only one upgraded to WordPress 2.1 so far. I wanted my solution to work with the new version of WordPress, so that’s the site I used for testing.
I referred to the WordPress Codex (of course), with its rather good template tag documentation. I won’t bore you with details about my research efforts. Frankly, I don’t remember exactly which tags I looked at, anyway. But the one that held the solution was get_the_category. It works within the Loop to retrieve information for all categories for a post. I fiddled around with it on the WordPress VQS site until I had the hang of it, and then re-created the code for my own site.