Tagadelic
Tagadelic is a small module, without any databases, or configuration, that generates a page with weighted tags. The cool thing is that by merely altering font sizes, these lists suddenly gain a dimension.
Tagadelic offers various ways to add terms and vocabularies in one tag cloud. By using the urls, you can create your own clouds pages.
It also offers a sideblock for each taxonomy tree.
Because examples are cooler to look at then PHP or ugly ASCIIart READMEs, we want your implementation of tagadelic. Please post it in a comment to this project.
We are testing a really nice third-party feature-request system. Please use FeVote to vote for- or add, your favorite Tagadelic features
Related modules
- tagadelic_views: Views implementation
- community_tags: Allows members of the community to tag other users' content.
Releases
| Official releases | Date | Size | Links | Status | |
|---|---|---|---|---|---|
| 6.x-1.2 | 2008-Dec-31 | 19.98 KB | Download · Release notes | Recommended for 6.x | |
| 5.x-1.1 | 2009-Mar-29 | 18.53 KB | Download · Release notes | Recommended for 5.x | |
| 4.7.x-2.0 | 2006-Nov-15 | 9.67 KB | Download · Release notes | Recommended for 4.7.x | |
| Development snapshots | Date | Size | Links | Status | |
|---|---|---|---|---|---|
| 6.x-1.x-dev | 2009-May-31 | 20.09 KB | Download · Release notes | Development snapshot | |
| 5.x-1.x-dev | 2009-May-14 | 18.67 KB | Download · Release notes | Development snapshot | |

Display number of tags
I've altered a line in the module so that the number of tags appears when you rest your mouse (or focus on) a term in the tag cloud.
In tagadelic.module (I'm using Drupal 5, $Id: tagadelic.module,v 1.36.2.3 2007/03/13 09:58:31 ber Exp $) line 293:
$output .= l($term->name, taxonomy_term_path($term), array('class'=>"tagadelic level$term->weight") ." \n";Change it to this:
$output .= l($term->name, taxonomy_term_path($term), array('class'=>"tagadelic level$term->weight", 'title'=>"Number of posts with this tag: $term->number_of_posts")) ." \n";You should of course do this as a theme override function (see http://drupal.org/node/55126), and leave your tagadelic module alone! To do that you would put the whole theme function (found at line 287 in the module) in your template.php file. (change (your theme name here) to well, the name of your theme and no brackets!):
/*** theme function that renders the HTML for the tags
* @ingroup themable
*/
function (your theme name here)_tagadelic_weighted($terms) {
foreach ($terms as $term) {
$output .= l($term->name, taxonomy_term_path($term), array('class'=>"tagadelic level$term->weight", 'title'=>"Number of posts with this tag: $term->number_of_posts")) ." \n";
}
return $output;
}
Hope this useful
displaying number of posts
Thank you. You can also simply display the number of posts (without having to hover the mouse).
(This code is from version 4.7)
$output .= l($term->name, taxonomy_term_path($term), array('class'=>"level$term->weight")) ."(".$term->number_of_posts.") \n";Post count in 6.x
The relevant code for version 6.x can be found on tagadelic.module, line 311:
Change from:
$output .= l($term->name, taxonomy_term_path($term), array('attributes' => array('class' => "tagadelic level$term->weight", 'rel' => 'tag'))) ." \n";to
$output .= l($term->name, taxonomy_term_path($term), array('attributes' => array('class' => "tagadelic level$term->weight", 'rel' => 'tag'))) ." (".$term->number_of_posts.") \n";Cheers for an excellent and highly useful module!
Exclude rather than Include categories
Sometimes, as an admin, it's much easier to figure out (and easier to see) what you DON'T want in a tag cloud, as opposed to figuring out what you want included (and being left wondering if something isn't showing up just because it wasn't popular enough, or if there's something wrong with your code). For those few, here's a solution:
Put this in your template file:
<?php
/**
* Function based on tagadelic module, but customized for afterl use
* @param array $excluded_vids An array of vocabulary ids to not include in the output
* @param int $number_of_tags The number of tags to output. If not set, or set to 0, will default to global tagadelic settings
* @param int $steps The number of gradations from maximum popularity to lowest. If not set, or set to 0, will default to global tagadelic settings.
*/
function hottest_tags($excluded_vids = array(), $number_of_tags = 0, $steps = 0) {
//Let's fire off an error if the tagadelic module is not installed
if (!module_exist('tagadelic')) return t('The hottest tags function requires the tagadelic module.');
if (empty($number_of_tags)) $number_of_tags = variable_get('tagadelic_page_amount', '60');
if (empty($steps)) $steps = variable_get('tagadelic_levels', 6);
// query adapted from tagadelic module (tagadelic_get_weighted_tags)
// returns a result set ordered by count, of tags NOT in passed categories.
if (empty($excluded_vids)) {
$result = db_query_range('SELECT COUNT(*) AS count, d.tid, d.name, d.vid FROM {term_data} d INNER JOIN {term_node} n ON d.tid = n.tid GROUP BY d.tid, d.name, d.vid ORDER BY count DESC', 0, $number_of_tags);
}
else {
$result = db_query_range('SELECT COUNT(*) AS count, d.tid, d.name, d.vid FROM {term_data} d INNER JOIN {term_node} n ON d.tid = n.tid WHERE d.vid NOT IN ('.substr(str_repeat('%d,', count($excluded_vids)), 0, -1) .') GROUP BY d.tid, d.name, d.vid ORDER BY count DESC', $excluded_vids, 0, $number_of_tags);
}
//build weighting using tagadelic's built-in code
$tags = tagadelic_build_weighted_tags($result, $steps);
//sort the tags per global tagadelic settings
return theme('tagadelic_weighted', tagadelic_sort_tags($tags));
}
?>
then, make a new block (content type PHP), and put this in there:
<?php
/** The following variables can be left unset, if desired, and the defaults from the tagadelic module will be used */
/** @var array $excluded vids To exclude categories (vocabularies), set it like this: array(catID, catID, catID) */
$excluded_vids = array(1,2,3,4,5,6,7,8,346,350);
/** @var int $number_of_tags How many tags do you want in the output? */
$number_of_tags = 0;//0 means: Use the tagadelic module's setting
/** @var int $steps How many steps of gradation between most popular and least popular? */
$steps = 0;//0 means: Use the tagadelic module's setting.
print hottest_tags($excluded_vids, $number_of_tags, $steps);
?>
We're using this on afterellen.com to great effect. Thanks to all the contributors on here who got me started in the right direction.
hey klktrk, do you know a
hey klktrk,
do you know a way to create a tagcloud only with tags submitted by an user?
regards
Lausch
Great site
and thanks for the code.
Hi Tyler Which version of
Hi Tyler
Which version of the tagadelic module are you using?
Many thanks
Dan
Hi, Dan! I think it's
Hi, Dan!
I think it's 4.6.x-1.x-dev
Very good but problem with unpublished nodes
I have a little problem:
Can Tagadelic show only Tags from Nodes with the status "published"? Because it shows all Tags even those from unpublished nodes.
Seconded
I second this request. I'm writing a blog and thought a tag cloud would make a great addition to the homepage. Unfortunately, I constantly create unpublished nodes to brainstorm in and work through to finished posts. As I write I add tags to the keywords category. Unfortunately these tags now appear in my tag cloud, but when clicked on return a page saying that there are no posts in this category.
Anything that can be done as far as the URL goes to make tagadelic ignore unpublished nodes?
Check issue queue
There's an issue for this, please check that out and post suggestions/patches there.
---
paul byrne
paul.leafish.co.uk | www.leafish.co.uk
Gradient Colors for different vocabularies
I am using different vocabularies in my page, and I wanted to:
Here's my website with the example: q14.net
Here's the code (use it for custom block):
<?php
$tags = array();
$styles = array();
$gradients = array();
// color gradients, from dark to bright
array_push($gradients, array('003300', '336633', '339933', '66cc66', '99ff99' ));
array_push($gradients, array('000033', '003366', '333399', '6666cc', '9999ff' ));
array_push($gradients, array('330000', '663300', '993333', 'cc6666', 'ee9999' ));
array_push($gradients, array('000000', '333333', '666666', '888888', '999999' ));
array_push($gradients, array('003333', '336666', '339999', '669999', '99cccc' ));
$color_counter = 0;
foreach(taxonomy_get_vocabularies() as $voc) {
foreach(tagadelic_get_weighted_tags(array($voc->vid)) as $tag) {
array_push($tags, $tag);
}
// set css
$css_out.=".t_number{ color: #999}";
for($i = 0; $i <= 10; $i++) {
$val = 0.7+$i/10;
$css = ".t".$voc->vid."_".$i." {font-size : ".$val."em }";
$css .=" .t".$voc->vid."_".$i.":link, .t".$voc->vid."_".$i.":visited { color: #".$gradients[$color_counter][count($gradients[$color_counter])-1].";}";
$css_out .= $css; // css should be in head actually
if(($i > 1)&&($i % 2 == 0)&& (count($gradients) > 0)) array_pop($gradients[$color_counter]);
}
$color_counter++;
}
print '<style type="text/css">'.$css_out.'</style>'."\n";
$tags = tagadelic_sort_tags($tags);
// own output method (not using tagadelic_theme()!!)
$output = '<span class="t_number">';
foreach ($tags as $term) {
$output .= ''.l($term->name, taxonomy_term_path($term), array('class' => "t".$term->vid."_".$term->weight));
$output .= '('.$term->number_of_posts.')'." \n";
}
$output .= '</span>';
print $output;
?>
tag sort order problem... and solution
When tags are using non 7bits chars, they are not sorted correctly.
In tagadelic.module, I made the following change to _tagadelic_sort_by_title in order to use mbstring to sort tags correctly (it works at least for french tags):
Maybe iconv could be used there.
Function "to7bit" comes from php.net.
/**
* @args string $text line of encoded text
* string $from_enc (encoding type of $text, e.g. UTF-8, ISO-8859-1)
*
* @returns 7bit representation
*/
function to7bit($text,$from_enc) {
if (isset($from_enc))
$from_enc = mb_detect_encoding($text,"auto");
$text = mb_convert_encoding($text,'HTML-ENTITIES',$from_enc);
$text = preg_replace(
array('/ß/','/&(..)lig;/',
'/&([aouAOU])uml;/','/&(.)[^;]*;/'),
array('ss',"$1","$1".'e',"$1"),
$text);
return $text;
}
/**
* callback for usort, sort by count
*/
function _tagadelic_sort_by_title($a, $b) {
if (extension_loaded('mbstring'))
return strnatcasecmp(to7bit($a->name), to7bit($b->name));
else
return strnatcasecmp($a->name, $b->name);
}
Depends on what you mean by main page
You can set your drupal frontpage to be /tagadelic in the settings, or if you want to get fancy you can use the frontpage.module (or your own theme trickery or one of the many other neato-front modules) to add this call to whatever makes your frontpage happen:
theme('tagadelic_weighted', tagadelic_get_weighted_tags(array($vocabulary->vid))));If you're doing this by hand, you'll want to replace $vocabulary->vid with the ID number of your tagging vocab.
------
Personal: Outlandish Josh
Professional: Chapter Three
Tagadelic:displaying all category/vocabulary tags in one block.
<?phpdrupal_set_html_head('<style type="text/css">@import url('.drupal_get_path('module','tagadelic').'/tagadelic.css);</style>');
$vocs[] = 3; // id of the vocabulary of which you want to display a tag cloud
$output = theme('tagadelic_weighted',tagadelic_get_weighted_tags($vocs));
print $output;
?>
This PHP snippet from bryght.com only displays tags from one particular vocabulary. Anyone know how I display all tags from all vocabularies in a block? Seems like it should be simple but I can't figure it out.
Thanks
Edit: I figured it out. $vocs[] needed to be initialized as an array with all the vocabulary numbers listed like so:
$vocs[] = 1;
$vocs[] = 2;
$vocs[] = 3; etc....
One line
You can do it on one line like this:
$vocs = array(1,2,3,4,5,6,7,8,9); // or whatever vocabularies you want