Tagadelic Snippet
Last modified: September 21, 2008 - 01:35
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;
?>
D6 version with "More" link
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.
<?phpdrupal_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;
?>
Please forgive a newbie
Please forgive a newbie question. How would the code look for selecting all vocabs instead of just array(3,4)?
modified to work with i18n
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";
?>
localized terms
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!
Wow, thanks, that code works
Wow, thanks, that code works fine!
<?phpdrupal_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!