WordPress, like other modern blogging systems, supports tags on posts and also lets you display a ‘tag cloud’ as a sidebar widget, where the most used tags are in larger text. But what if you want a tag cloud as a separate page, and not just in the sidebar?
I’m writing this guide as I couldn’t find a decent, clear guide when creating my own tag cloud page, although the information is cobbled together from A very easy WordPress Tag Cloud page and the WordPress Codex on wp_tag_cloud().
First of all, you will need to create a file called tags.php and upload it to your current theme folder, i.e. /wp-content/themes/themename/ . So if you’re using the default Twenty Ten theme with WordPress 3.1.x, you would upload the file to /wp-content/themes/twentyten/tags.php . You then need to past in some code to this file:
<?php /* Template Name: Cloud */ get_header(); ?> <?php get_header(); ?> <!-- Start tag cloud --> <h2>Tag Cloud</h2> <?php $args = array('number' => 45); wp_tag_cloud($args); ?> <!-- End tag cloud --> <?php get_sidebar(); ?> <?php get_footer(); ?>
I’m showing the code that is compatible with the default theme but you may need to change this if you use a different one – in your WordPress dashboard, select the ‘Editor’ link under ‘Appearance’ and open up ‘Page Template’ to see how the page is laid out. The important bits to copy from my example are the code at the top, identifying the page, and the actual tag cloud, again marked out with comments.
Save that file. If you want, you can make it writeable, as then you’ll be able to edit it from within the WordPress dashboard, again under Appearance > Themes where it’ll be called ‘Cloud’.
Next, we need to create a page, co under ‘Pages’ select ‘Add new’. Call it ‘Tag Cloud’, or whatever you want. Leave the actual page content blank, but before saving it, on the right hand side set ‘Template’ to ‘Cloud’. Then save it. Now, you should have a tag cloud.
wp_tag_cloud() function is quite flexible and offers a number of options to change how it appears – have a look at its options on the WordPress Codex if you want to play with it. In the example above, I’ve set the number of tags to be shown as 45, by using
$args = array('number' => 45); but you can change this to any number you like. You can also change the text size, the order, or exclude some tags.