About fluffly TagClouds

Tuesday, November 25, 2008

Do you know the tag cloud in my right sidebar? Probably you are interested in an easy way to create to? Well that isn't really that hard, at least not with the next version of the Zend Framework. A few days ago, I have created a proposal for Zend_TagCloud, after I received an e-mail from a user asking me, how the tag cloud on my website works.

Well long story short, I quickly sticked a prototype together, which supplies you with a basic HTML decorator, which allows nearly any kind of HTML tag cloud. Additonally, you can create your own decorators very easily. The usage of the tag cloud component is even simpler than anyone could describe it. Let some code speak for it:
<?php
$tags = array(
    array('title'  => 'Tag 1',
          'weight' => 50,
          'url'    => '/tag/1'),
    array('title'  => 'Tag 2',
          'weight' => 20,
          'url'    => '/tag/2'),
    array('title'  => 'Tag 3',
          'weight' => 34,
          'url'    => '/tag/3'),
);

$cloud = new Zend_TagCloud(array('tags' => $tags));
echo $cloud;
And yeah, that's it. No fancy magic. You simply give an array of tags to it and it works. You can also specify some options. For instance which decorators to use for the tags and for the cloud, and also give options directly to the decorators. The decorators allow you to specify a list of tags and optionally attributes to assign to the tags. The default tag decorator creates at least an anchor element with the defined URL as href and the tag title as content.

Right now, you may want to take a look at the Zend_Tag_Cloud proposal or checkout the Zend_TagCloud prototype from svn.

Comments to this article

  • Avatar of robo47 Reply robo47 Monday, December 29, 2008 12:24 PM

    I think the current Revision of the Code in the SVN is not really working Code ?

    First Problem was in the constructor:

    $this->setCloudDecorator('cloudHtml');

    should be

    $this->setCloudDecorator('HtmlCloud');

    then
    $this->setTagsDecorator('tagHtml');

    wrong method-name and param:

    $this->setTagDecorator('HtmlTag');

    and then i got

    Notice: Undefined property: Zend_TagCloud::$_weightKey in /path/Zend/TagCloud.php on line 286

    Is there anywhere a working prototype ? Or an older Revision in svn which i can checkout which is working ?

    greetz
    robo47

Leave a comment

Please note that your email address will not be shown, it is only used to fetch your avatar image from gravatar.com and for notifications.

                             _ 
 _ __   __ _ _   _ _   _ ___(_)
| '_ \ / _` | | | | | | |_  / |
| | | | (_| | |_| | |_| |/ /| |
|_| |_|\__,_|\__,_|\__,_/___|_|