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.