Posts

tag cloud using wp-cumulus 06 Jul 2010
Tags: tag cloud, wp-cumulus, swf, wordpress

This tutorial is derived from the wp-cumulus plugin of wordpress. You can see the implementation on the sidebar.

First, download the wp-cumulus archive at wordpress.

Copy the tagcloud.swf to the public directory

Also, be sure to include the swfobject javascript file on the head tag.

Then for every page that you want to place your tag cloud, add the following code. Be sure to have a div with an id 'flashcontent' or change the parameter of the last line in the script below to whatever id you want.

haml
:javascript
  var so = new SWFObject("/tagcloud.swf", "tagcloud", "180", "180", "7", "#336699");
  so.addParam("wmode", "transparent");
  so.addVariable("mode", "tags");
  so.addVariable("distr", "true");
  so.addVariable("tcolor", "0xd2691d");
  so.addVariable("tcolor2", "0x555555");
  so.addVariable("hicolor", "0xffffff");
  so.addVariable("tagcloud", "#{Tag.counts.collect {|tag| "<a href="#{tag_url(tag.name)}">#{tag.name}</a>"}.join}");
  so.write("flashcontent");

As you can see, the second-to-the-last line of the script is where we create the tag links. I'm using acts_as_taggable_on_steroids plugin to manage my tags. But as long as you can create a method that returns a concatenated array of tags, that should be fine.