WordPress Guy

WordPress Guy designs and develops WordPress themes and plugins. WordPress Guy teaches you WordPress stuff.

Have you noticed that many blogs have a tag cloud in their sidebars? however, not many have a tag cloud page. Why a tag cloud page you may ask! Well… many reasons: de-cluttering your sidebar, adding interactivity to your blog, … Or maybe you have so many tags that they don’t fit in your regular tag cloud widget.

So that’s what this tutorial is about: creating a tag cloud page.

Before we start

Before we start, you need to be running WordPress version 2.3 or later, and of course have a bunch of posts with tags, otherwise you may end up with an empty tag cloud.

Creating the page template

First, we need to create a custom page template. A page template is nothing more than a PHP file with a special commented code at the beginning of the file.

Go ahead an create a new php file and name it “tagcloud.php” or whatever you want. Now put the following at the beginning of it:

<?php
/*
Template Name: Tag Cloud
*/
?>

With this we’re telling WordPress that our tagcloud.php file is a page template and it’s name is “Tag Cloud”.

The basic structure

Now let’s add the basic page structure, header, sidebar and footer. Of course, this depends on the theme you’re using. I’m just going to assume we’re using the Kubrick theme structure for this tutorial. I recommend you open the page.php file of your theme and try to replicate it. The resulting file might look something like this:

<?php
/*
Template Name: Tag Cloud
*/
?>
 
<?php get_header(); ?>
 
    <div id="content" class="narrowcolumn">
 
    </div>
 
<?php get_sidebar(); ?>
 
<?php get_footer(); ?>

That would print an empty page because we haven’t inserted the template tag yet.

The template tag

Now we need to put in the tag cloud template tag: wp_tag_cloud(), which will print the tag cloud. You can find more information on the wp_tag_cloud() template tag in the codex.

Okay, let’s add the template tag:

<?php
/*
Template Name: Tag Cloud
*/
?>
 
<?php get_header(); ?>
 
    <div id="content" class="narrowcolumn">
 
        <div class="tag_cloud">
            <?php wp_tag_cloud('number=0'); ?>
        </div>
 
    </div>
 
<?php get_sidebar(); ?>
 
<?php get_footer(); ?>

Notice that we entered “number=0” parameter, this is because, by default, the wp_tag_cloud() template tag only prints the 45 most used tags, and we want to display them all instead.

Also, we’ve placed the template tag inside a div with a class of “tag_cloud” in case we need to style it later with some CSS.

We’re done with the PHP part, now save your file and upload it to your theme directory (wp-content/themes/your_theme_name).

Creating a new page in WordPress

All we need to do now is create the page in WordPress. To do this, you just have to follow these steps:

  1. Go to the Write » Page section of the admin panel.
  2. Type a descriptive title for the page in the Title field.
  3. Locate the Page Template panel, open it if it’s closed, and choose “Tag Cloud” from the drop-down menu.
  4. Hit the Publish button.

And we’re done. Feel free to post your thoughts and questions in the Comments section.

Comments

  • May 15th, 2008 at 7:46 pm

    Cool idea. I love the tag cloud, but hate the way it hogs space on my sidebar.

  • June 3rd, 2008 at 7:19 am

    First of all… GREAT site! I just found it via Weblog Tools Collection (and I’m definitely going to try your Pistachio theme). I do have my tag archive done the way you explained it, yet, I’ve been cracking my head with something. I just to have a really cool tag archive using and add on for Ultimate Tag Warrior. When UTW became obsolete, the functions were lost.

    The add on displayed the tags in a list format, which you can also do with the wp_tag_cloud tag, but I can’t figure out a way to make the columns show as the add on did. Since I saw you modified an Alex King plug in, would it be too much to ask you to take a look at the add on code? I hope you can! (link)

    Again, thank you for the site, I found a couple tricks I’m going to try.

  • June 3rd, 2008 at 1:07 pm

    @Fer: I have never used the Ultimate Tag Warrior plugin, but, I found this site which offers a version of the plugin that still allows you to use the plugin functions, but with the native WordPress tags. Maybe that’ll work for you.

    Oh… and thanks for the compliments ;-)

  • June 3rd, 2008 at 7:19 pm

    Thanks for the tip, I’ll give it a try!

  • June 27th, 2008 at 5:34 am

    ... How to make a tag cloud page | WordPress Guy (tags: wordpresstutorial via:mento.info) ...

  • July 5th, 2008 at 2:12 am

    thank you! so easy to follow! i just have to figure out how to remove the unsightly link underlines that show up, but hopefully a quick html tag will fix that! i’m also going to try and get some archiving going like this: http://www.srah.net/weblog/archives.php
    thanks again!

  • August 11th, 2008 at 3:49 pm

    Thanks!
    Beautiful instructions, very easy to follow
    E.

  • October 12th, 2008 at 1:42 pm

    nice tips..it’s work in my blog

  • ... Theme 2. ขอบคุณ wpguy และ staygolinks ...

  • October 16th, 2008 at 3:25 am

    ... the original code for the categories (which I don’t use anymore) - with some help from WordPress Guy’s quick tutorial on the subject. Dropping the code in and just inserting a “50″ ...

  • October 31st, 2008 at 1:39 am

    Well done - I was after this as a plug in and looked for ages. So I have found this instead, I had no idea that I had this many tags. Only down side is - I don’t know how effective this will be for the google bot or SEO purposes.

    But great guide and straight forward !!

Your Comment