Tag Cloud on Its Own Page

I’m fond of tag clouds. When the blog writer labels each blog post with relevant tags, the word cloud shows at a glance the topics that get a lot of coverage. They’re also visually interesting, with font size showing how often a tag is used. It’s an automatically generated infographic!

WordPress has a widget for putting a tag cloud in your sidebar, but if you site has a lot of posts and a variety of tags, it can be cramped-looking or take up too much of the sidebar space. You can give it the space it deserves on a dedicated tag cloud page.

You need a WordPress page template, which involves a little bit of php coding, and a page, which you define in the WordPress Dashboard.

Page Template

A WordPress page template tells WordPress how to lay out each page. It chooses which template to use based on the template’s filename. For the tag cloud page, the template’s name is tagcloud.php. Use a text editor, not a word processing program, to create the file.

Here’s my tag cloud template:

<?php
/**
 * Template Name: Tag Cloud
 */
?>
<?php get_header(); ?>
 
<div id="primary" class="content-area">
   <article class="tag_cloud">
     <header class="entry-header">
	<?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
     </header>
 
     <div class="tag_cloud">        
        <?php wp_tag_cloud('number=0'); ?>
     </div>    
   </article>	
</div>
 
<?php get_sidebar(); ?>
<?php get_footer(); ?>

What’s in the Template

The usual template tags

After the intro comments,  get_header() at the beginning and get_sidebar() and get_footer() at the end bring in the standard parts of a WordPress layout. The main content area contains an “article” section. Inside the articlde is  a “header” section for the page title and a div that holds the tag cloud.

CSS Styling

To make your template match the rest of your theme, you’ll want to use ids and classes from your theme. If you add a tag_cloud class around the call to wp_tag_cloud(), you can use it to specify CSS styling for the cloud.

wp_tag_cloud()

The WordPress template tag wp_tag_cloud has many possible arguments, including smallest and largest font sizes, space between tags, and tags to include or exclude. Here, “number” is all we need. It specifies the number of tags to include. The default is 45 tags (keeping the tag cloud small enough for the sidebar, I suppose). We’re specifying 0, which means show all tags.

Where to save the template

Using an FTP file-transfer program or your web-hosting dashboard, put your template file in your WordPress site. It belongs in  your WordPress theme directory:

wp-content/themes/your-theme-name/tagcloud.php

Tag Cloud Page

The second part is really easy. All you need is an empty WordPress page that uses the tag cloud template.

  1. Log in to your WordPress dashboard.
  2. Create a new page.
  3. Specify a page title. You don’t need anything in the content area.
  4. In the Page Attributes section, choose “Tag Cloud” from the Template menu.
  5. Click Publish to save the page and make it available on your website.

You’ll want to put the Tag Cloud page on a menu or add a link in a sidebar. Make sure to put interesting tags on your posts!

Thanks to the WordPress Guy blog for an excellent step-by-step  article on making a tag cloud page.

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.