hi all,
this is a version of the tag clouds
for 4images...
this little mod display a cloud of keyword (see
here for categories), sort by quantity (the more the keyword is used in the gallery, bigger will be the font).
only real keywords : i mean
no keywords from name or descriptionyou can see a demo on my site.
first : backup your files and
STEP1 : open
includes/page_header.phpand add at the very end
before ?>:
$site_template->register_vars(array(
"lang_keyword" => $lang['keywords'], //---[/[MOD] Tag Clouds]
"show_tag_clouds" => get_tag_clouds() //---[/[MOD] Tag Clouds]
));
STEP2 : open
includes/functions.phpand add at the very end
before ?>:
//---[ [MOD] Tag Cloud]
function get_tag_clouds() {
global $site_db, $lang, $site_sess, $mode;
$output = "";
$sql = "SELECT i.word_id, i.word_text, COUNT(c.word_id) AS quantity
FROM ".WORDLIST_TABLE." i
LEFT JOIN ".WORDMATCH_TABLE." c ON i.word_id = c.word_id
WHERE keys_match > 0
GROUP BY i.word_text
ORDER BY RAND()
LIMIT 20";
$result = $site_db->query($sql);
while ($row = $site_db->fetch_array($result)) {
$tags[$row['word_text']] = $row['quantity'];
}
//uncommentnext line to sort the tag array in reverse order (+ => -)
//arsort($tags);
$max_size = 250; // max font size in %
$min_size = 50; // min font size in %
// largest and smallest array values
$max_qty = max(array_values($tags));
$min_qty = min(array_values($tags));
// find the range of values
$spread = $max_qty - $min_qty;
if ($spread == 0) { // we don't want to divide by zero
$spread = 1;
}
// set the font-size increment
$step = ($max_size - $min_size) / ($spread);
// loop through the tag array
foreach ($tags as $key => $value) {
// calculate font-size
// find the $value in excess of $min_qty
// multiply by the font-size increment ($size)
// and add the $min_size set above
$size = round($min_size + (($value - $min_qty) * $step));
$output .= '<a href="'.$site_sess->url(ROOT_PATH."search.php?search_keywords=".$key.((!empty($mode)) ? "&mode=".$mode : "")).'" style="font-size:'.$size.'%;color:rgb('.mt_rand(0, 255).', '.mt_rand(0, 255).', '.mt_rand(0, 255).');font-family:Verdana, Arial, Helvetica, sans-serif;" title="'.$value.' '.$lang['tagged_with'].' '.$key.'">'.$key.'</a> ';
}
return $output;
}
//---[/[MOD] Tag Cloud]
read the comments and change some setting and styles to fit your needs
last step , open main.php in your language dir and add at the end:
$lang['tagged_with'] = "image(s) with tag: ";
now add the 2 tags
{lang_keyword} and
{show_tag_clouds} anywhere in you template.
PS: for all the users who love statistics, the cloud tag can take other parameters than mine... just found the query and change it in function.php
see
here to find how to do this tag cloud with categories