wordpress : Listing tags like wp_list_categories


When I started building this site, I decided to keep my UI really minimal so as to keep focus on the content. But you have to leave some navigational hints, or it is easy to become disorientated. To fit in with the sort of minimalist 'style' I chose a simple - but hopefully still obvious - highlight whereby the section of the siite you are currently looking at is highlighted in a darker color in the navigation menus.

I also extended this to the blog section, adding the same highlight rules to categories. This is made easy by the wp_list_categories() function which helpfully adds a css class, current-cat, to the currently selected category (if any).

I wanted to extend this to both archive and tag links, however the wp_get_archives() function doesn't support this, and there isn't (AFAIK) a wp_list_tags() function at the time of wrting.

There's an interesting workaround for wp_get_archives() on the wordpress support forums here which did the trick quite nicely.

That still left me with a lack of wp_list_tags() though, so I put on my PHP hat and knocked one up. It shares, via the underlying get_tags() function, a subset of option parameters with wp_list_categories(), and I added a 'show_count'. See the codex dox on get_tags() for a full list of options.

It doesn't currently share the bounteous crop of $arg parameters enjoyed by wp_list_categories(), but it certainly plugged my particular gap. To use this code, you need to insert it into your theme's functions.php file.




Codemonkey, iOS developer, neophyte entrepreneur, frequent hat wearer. Founder of Enigmatic Ape (@EnigmaticApe). Recidivist tea drinker. Sound tennis noob with NEVITC. Now available in Twitter, and ADN



Built With Bootstrap
Powered By Wordpress
Coded By Enigmatic Ape