Last updated October 22, 2011. Created on July 9, 2007.
Edited by MGParisi, add1sun. Log in to edit this page.

Here's a snippet I've been using under 5.1.

It combines terms from 3 vocabularies. You'll have to change the code accordingly. I hope this is useful.

<?php
$tagcloud
= "";
drupal_set_html_head('<style type="text/css">@import url('.drupal_get_path('module','tagadelic').'/tagadelic.css);</style>');
$vocs= array(4,5,410); //  ids of vocabs for which you want to build a tag cloud
$tagcloud = theme('tagadelic_weighted',tagadelic_sort_tags(tagadelic_get_weighted_tags($vocs)));
print
$tagcloud;
?>

tagadelic_get_weighted_tags() also takes the arguments steps (default of 6) and size (default of 60), in case the defaults are too much for you.

So if you wanted to show only 10 tags perhaps in a sidebar block you would add the parameter $size = 10
like so below:

<?php
$tagcloud
= "";
drupal_set_html_head('<style type="text/css">@import url('.drupal_get_path('module','tagadelic').'/tagadelic.css);</style>');
$vocs= array(4,5,410); //  ids of vocabs for which you want to build a tag cloud
$tagcloud = theme('tagadelic_weighted',tagadelic_sort_tags(tagadelic_get_weighted_tags($vocs, $steps = 6, $size = 10)));
print
$tagcloud;
?>

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.

Comments

financialgeek’s picture

I think for Drupal 6 it'd be better to call drupal_add_css to add the css file. Also, I added the 'More' link.

<?php
drupal_add_css
('/'.drupal_get_path('module','tagadelic').'/tagadelic.css');
$vocs= array(3,4); //  ids of vocabs for which you want to build a tag cloud
$vids= implode(",",$vocs);
$tagcloud = "";
$tagcloud .= theme('tagadelic_weighted',tagadelic_sort_tags(tagadelic_get_weighted_tags($vocs, $steps = 6, $size = 12)));
$tagcloud .= theme('tagadelic_more', $vids);
print
$tagcloud;
?>
boborg’s picture

Please forgive a newbie question. How would the code look for selecting all vocabs instead of just array(3,4)?

scottop’s picture

Thank you for the snippet. I had to modify it to work with different languages. My site is in three languages, and each language has its own tag vocabulary. So the block had to pull up a different vocabulary for each language. Nothing worked right in Drupal 5.x, so I wrote my own block code. I thought it might be useful to others:

<?php
$language
= substr($_REQUEST['q'],0,2);
$tagcloud = "";
drupal_set_html_head('<style type="text/css">@import url('.drupal_get_path('module','tagadelic').'/tagadelic.css);</style>');
switch (
$language) {
    case
"es":
       
$vocs= array (5);
       
$tagcloud .= "Temas noticias:<br />";
       
$link = l("mas temas","tagadelic/chunk/5");
        break;
    case
"fr":
       
$vocs= array (4);
       
$tagcloud .= "News thèmes:<br />";
       
$link = l("plusieurs thèmes","tagadelic/chunk/4");
        break;
    default:
       
$vocs=array(3);
       
$tagcloud .= "News tags:<br />";
       
$link = l("more tags","tagadelic/chunk/3");
}
$tagcloud .= theme('tagadelic_weighted',tagadelic_sort_tags(tagadelic_get_weighted_tags($vocs, $steps = 6, $size = 20)));
print
"$tagcloud\n<p align='right' >$link</p>\n";
?>
milos1234’s picture

Hi there, do you think this would work with localized vocabulary terms in i18n?
i have one vocaubulary for ALL languages, but the terms are localized and translatable.
Many thanks, ive been searching everywhere!

witzel’s picture

Wow, thanks, that code works fine!

<?php
drupal_add_css
('/'.drupal_get_path('module','tagadelic').'/tagadelic.css');
$vocs= array(3,4); //  ids of vocabs for which you want to build a tag cloud
$vids= implode(",",$vocs);
$tagcloud = "";
$tagcloud .= theme('tagadelic_weighted',tagadelic_sort_tags(tagadelic_get_weighted_tags($vocs, $steps = 6, $size = 12)));
$tagcloud .= theme('tagadelic_more', $vids);
print
$tagcloud;
?>

How do i have to change the code, if i want to show the terms of a vorabulary that the viewed node was tagged with?
Thank you!

cmejo’s picture

Will this work in d6?

Lead Developer and Owner, boncera
www.boncera.com