Display tags as cloud

Creates a cloud of your used tags. Didn't test on Drupal 4.6 but should work too.

Instead of this snippet you can just install the tagadelic module.

<?php
class tag
{
    var
$name = "";
    var
$count = 0;
    var
$tid = 0;

    function
getCount()
    {
        return
$this->count;
    }
    function
getName()
    {
        return
$this->name;
    }
    function
setCount($var)
    {
       
$this->count = $var;
    }
    function
setName($var)
    {
       
$this->name = $var;
    }
    function
setTID($var)
    {
       
$this->tid = $var;
    }
    function
getTID()
    {
        return
$this->tid;
    }

}
$count = 0; // Overall count of used tags
$threshold = 1; // How many tags are needed to get displayed
$font_size = 0.8;
$query = "SELECT d.name,d.tid FROM {term_data} d, {term_node} dn WHERE dn.tid=d.tid;";
$result = db_query($query);
$tags['Test'] = 0;
while(
$node = db_fetch_array($result))
{
    if (
$tags[$node['name']] == NULL)
    {
       
$tags[$node['name']] = new tag();
       
$tags[$node['name']]->setName($node['name']);
       
$tags[$node['name']]->setCount(1);
       
$tags[$node['name']]->setTID($node['tid']);
       
$count = $count + 1;
    }
    else
    {
       
$tags[$node['name']]->setCount(
           
$tags[$node['name']]->getCount() + 1
       
);
       
$count = $count + 1;
    }
}
foreach(
$tags as $tag)
{
   
$mycount = $tag->count;
    if(
$mycount > $threshold)
    {
       
$fraction = ((int)(($mycount / $count) * 1000)) / 10;
        if(
$fraction < $font_size)
        {
           
$fraction = $font_size;
        }
        echo
'<span style="font-size: ' . $fraction . 'em;">' . l($tag->name,'taxonomy/term/' . $tag->tid,array('title="' . $tag->count . ' Nodes"')) . '</span> ';
    }
}
?>

In Drupal 5.1, for the font

doc2@drupalfr.org - July 9, 2007 - 15:01

In Drupal 5.1, for the font size to fit your block, one the latest line should be:
        $fraction = ((int)(($mycount / $count) * 100)) / 10;

instead of
        $fraction = ((int)(($mycount / $count) * 1000)) / 10;

This snippet does not check against taxonomy_access module

innovationcreation - September 14, 2007 - 16:06

in drupal 4.7.x This snippet does not check against taxonomy_access module database. If you list a tag to not be listed on a node (via taxonomy_access module http://drupal.org/project/taxonomy_access) it will still show up as listed in this snippets cloud.

 
 

Drupal is a registered trademark of Dries Buytaert.