Displaying Custom WordPress Category/Tag Lists

Filed in Web DevelopmentTags: Geekery, Web Site, WordPress
Custom Category/Tag List Screenshot

Custom category list with RSS feed links and post counts

In my sidebar, I have displayed lists of categories and tags, but wanted to have greater control over these lists than what is offered by the currently available template tags. Namely, I wanted to be able to display each category/tag with a link to the RSS feed on the left, and a post count on the right. So, based on a helpful blog post, my own meanderings in this WPTavern forum thread, and help from DD32 and mfields in this WPTavern forum thread, I have custom category and tag lists, complete with links to the RSS feeds and total post counts for each category and tag.

Here's how:

Custom Category List

Add the following code to your sidebar, or into a widget:

<ul class="leftcolcatlist">
<?php
$catrssimg = "/images/rss.png";
$catrssurl = get_bloginfo('template_directory') . $catrssimg;
$customcatlist ='';
$customcats=  get_categories();
foreach($customcats as $customcat) {
$customcatlist = '<li><a title="Subscribe to the '.$customcat->name.' news feed" href="'.get_bloginfo('url').'/category/'.$customcat->category_nicename.'/feed/"><img src="'.$catrssurl.'" alt="feed" /></a><a href="'.get_bloginfo('url').'/category/'.$customcat->category_nicename.'/">'.$customcat->name.'</a> ('.$customcat->count.')</li>';
echo $customcatlist;
}
?>
</ul>

Custom Tag List

Add the following code to your sidebar, or into a widget:

<ul class="leftcolcatlist">
<?php
$tagrssimg = "/images/rss.png";
$tagrssurl = get_bloginfo('template_directory') . $tagrssimg;
$customtaglist =''; $customtags =  get_tags();
foreach($customtags as $customtag) {
$customtaglist = '<li><a title="Subscribe to the '.$customtag->name.' feed" href="'.get_bloginfo('url').'/tag/'.$customtag->slug.'/feed/"><img src="'.$tagrssurl.'" alt="feed" /></a><a href="'.get_bloginfo('url').'/tag/'.$customtag->slug.'/">'.$customtag->name.'</a> ('.$customtag->count.')</li>';
echo $customtaglist;
}
?>
</ul>

Modifications

You will need to modify $tagrssimg and $catrssimg depending on which RSS image you choose to use, and where you upload that image. If you use an image outside of your theme directory, you will also need to modify $tagrssurl and $catrssurl accordingly.

Yet To Come

Eventually, I will release a series (and/or collection) of widgets, including the above two custom lists.

Feedback

Comments (Comments are closed)

3 Responses to “Displaying Custom WordPress Category/Tag Lists”
  1. chip_bennett says:

    Displaying Custom WordPress Category/Tag Lists – http://www.chipbennett.net/wordpress/201

  2. Sue says:

    Thanks for the info Chris. Will possibly be using it in my WP blog in the near future!

  3. Sue says:

    Thanks too Chris for the info (as a link) to Twitoaster

Trackbacks

  1. How To Return Tag Slug - WordPress Tavern Forum