How to make a WordPress tag archive
My how to make an archive page post the other day inexplicably and inexcusably neglected to include consideration of tags. This post should put that right.
Adding a list of tags to your archives is actually pretty easy, but it uses a function you might not expect: wp_tag_cloud, which has a useful "format" parameter, allowing you to output a list of tags either as a list, or "flat" - just separated by whitespace. The "list" option outputs an unordered list, already wrapped in <ul> tags with the class wp-tag-cloud. Whichever format you choose, the tags are automatically hyperlinked.
To make a normal looking list, you'll need to turn off the font sizing that tag clouds use to make more popular tags larger. The easiest way to do this is to set both "smallest" and "largest" (font) parameters to 100, and the unit (of measurement) to % - everything in your list is 100% of the font size you'd expect it to be. Here's what I'm using on my own archive page:<?php wp_tag_cloud('format=list&smallest=100&largest=100&unit=%&number=0'); ?>
By default, wp_tag_cloud displays up to 45 tags: override this with the "number" parameter; 0 displays all tags. The "orderby" parameter can sort your list by name (alphabetical; the default) or count. There's more about wp_tag_cloud in the Codex.
Thanks to David from Far from Moscow for asking the question.
Tags: Add new tag, archives, wp_tag_cloud
Posted by Sue on May 11, 2009 in WordPress.







