Implement tag cloud is easy in Drupal. You can find the module called Tagadelic in the my previous post.
Drupal 7 – Create a Tag Cloud with Tagadelic
But the term path inside the tag cloud is always fixed as default which is taxonomy/term/[tid]. I tried to override it by the Entity Path module but no luck. Luckily i find a workaround to override it. Actually Tagadelic is not just a simple Drupal module but also a API system. The following theme function theme_tagadelic_weighted() determines the term path in Tagadelic.
<?php
function <THEME>_tagadelic_weighted(array $vars) {
$terms = $vars['terms'];
$output = '';
foreach ($terms as $term) {
$output .= l($term->name, 'taxonomy/term/' . $term->tid, array(
'attributes' => array(
'class' => array("tagadelic", "level" . $term->weight),
'rel' => 'tag',
'title' => $term->description,
)
)
) . " \n";
}
return $output;
}
?>
For example, i want to override a taxonomy term with machine name blog_tag so i added the following function in my theme template.php
function <THEME>_tagadelic_weighted(array $vars) {
$terms = $vars['terms'];
$output = '';
if ($vars['voc']->machine_name == 'blog_tag') {
// Override the path only if the vocabulary of the tag cloud is Blog Tag
foreach ($terms as $term) {
// The new path is a view page path with term id as argument input
$output .= l($term->name, 'blog-tag-view/' . $term->tid,
array(
'attributes' => array(
'class' => array("tagadelic", "level" . $term->weight),
'rel' => 'tag',
'title' => $term->description,
)
)
) . " \n";
}
} else {
// Default path for other vocabularies
foreach ($terms as $term) {
$output .= l($term->name, 'taxonomy/term/' . $term->tid,
array(
'attributes' => array(
'class' => array("tagadelic", "level" . $term->weight),
'rel' => 'tag',
'title' => $term->description,
)
)
) . " \n";
}
}
return $output;
}
Done =)
Reference: Lullabot API – theme_tagadelic_weighted
