Tag Cloud, an add-on for the tags mod
filed under: sNews CMS / Hacks & Mods
Be sure to check out the improved tag cloud first!
This is a tag cloud function I whipped up this afternoon. I did this very quickly, so I'm sure it could be improved upon. Copy the function below to your snews.php file, just above the closing tag.
You can change the minimum and maximum percentages if you like. To use, you simply call the function in your index.php like this;
<?php echo get_tagcloud(); ?>
or if you want to call it from inside an article, extra, or page, you insert it like this;
[func]get_tagcloud:|:[/func]
If you're using my tags mod version 1 and want to continue using that, simply replace the highlighted text with ?search_query= instead of tag/
function get_tagcloud() {
$max_size = 300; // max font size in %
$min_size = 100; // min font size in %
$sql = "SELECT keywords_meta FROM "._PRE."articles WHERE date <= NOW() AND published='1' AND visible = 'YES' AND keywords_meta != ''";
$result = mysql_query($sql);
$count = mysql_num_rows($result);
$x = "1";
while ($row = mysql_fetch_array($result)) {
if ($x < $count) {
$suffix = ", ";
} else {
$suffix = "";
}
$tagslist .= $row['keywords_meta'].$suffix;
$x++;
}
$tagslist = explode(", ",$tagslist);
asort($tagslist);
$tagslist = array_count_values($tagslist);
$max_occur = max(array_values($tagslist));
$min_occur = min(array_values($tagslist));
$range = $max_occur - $min_occur;
if ($range == 0) {
$range = 1;
}
$step = ($max_size - $min_size) / ($range);
echo '<div class="tagcloud"><p>';
// loop through the tag array
foreach ($tagslist as $key => $value) {
$fontsize = round($min_size + (($value - $min_occur) * $step));
echo '<a href="'._SITE.'tag/'.urlencode(strtolower($key)).'/" style="font-size: '.$fontsize.'%" title="'.$value.' items tagged with '.$key.'">'.$key.'</a> ';
}
echo '</p></div>';
}
Everything is contained in a div with the class of "tagcloud", so you can add that to your stylesheet. Here is a demo of the output from my site
1024x600 1404 AD 1503 AD 404 AP9617 AP9618 APC Acer Aspire One Ajax Anno 1404 Anno 1503 Arx Fatalis Avatar Beyond Divinity Bioshock Borderlands Boxter CSS CoD Command and Conquer Dawn of Discovery Debian Diablo Dragon Age: Origins FPS Fallout Feedburner Freelancer God of War Google IE Iron Man 2 Jagged Alliance Linux Lionheart Mass Effect Matrix Matt Jones Mini Cooper Modern Warfare 2 MySQL Nikon PC games PHP Patrician Pirates Porsche Port Royale Project Honey Pot RPG RSS RTS Red Dead Redemption Red Faction SD Card Sid Meier Sim City 4 Smart-UPS Sphider Starcraft Stronghold Tropico Tux Twitter UPS VPS WiFi Windows 7 Windows XP Zenwalk accessories ajax rating ajax stars archive black blogging brown bugs caching captcha cars categories clean comments content management dark descriptions design did you mean downloads email females fields games girls gloomy gravatars grunge hacks hibernation htaccess http:BL icons jQuery javascript keywords landscape linode mdj.us meta tags minimal mod_rewrite mods mootools movies nature netbook gaming netbook wallpapers netbooks pages polls privacy policy professional related articles replace retweet sNews search security social bookmarks social media spam substring suggestions tags templates themes update vacation wallpapers women
4 comments
Add a new comment »Categories
Recent Entries
Recent Comments
- Redbeard (I managed to get Vampire: The Masquerade - Bloodlines ...)
- Tina (Installed this today and working like a charm :) Thanks!)
- Tina (Thanks for this great mod :) Working on my site for quite a ...)
- konga (Hi Matt, if you plan to update it, please have a look into ...)
- David (Yo Matt, I have a problem, when I use this mod. ...)
- Dave (Have a Toshiba NB305. Win7 starter would not do screen ...)
- Daichisan (Howdy Matt, I dont really get it, whats ...)
- Matt (Mine is just customized further, that's all :) It just spits ...)
- Matt (David, Do you own or admin the server? Do you have exec ...)
Popular Entries
- Compact archives for sNews 1.7 (5/5)
- Light-weight related articles mod for sNews 1.7 (4.78/5)
- SEF / SEO search for your sNews website (4.75/5)
- 1024x600 netbook wallpapers of Evangeline Lilly (4.67/5)
- Gravatar mod for sNews 1.7 (4.67/5)
- An improved tag cloud for sNews 1.7 (4.67/5)
- Image / math hybrid captcha version 2, vastly improved (4.64/5)
- An easy mod to create custom break titles for your sNews articles (4.6/5)
- Command & Conquer Generals, and the Zero Hour expansion on the Acer Aspire One netbook (4.6/5)
Feb 7th, 2009 at 4:09 am
wow, well done Matt !
It looks very good, now I only need more "spare time" to be able to modify my sNews with all your mods ;)
Your mods are useful and really improve sNews, thanks again Matt
Feb 7th, 2009 at 2:39 pm
Thanks Sven, I appreciate the comments from yourself and others, makes it worthwhile.
Feb 14th, 2009 at 2:29 am
I'm a fan now.
That one is the ultimate Tag Clod Mod for sNews. ;-)
One thing, i think tags links should not be adjacent, so ine the last echo it needs a | to separate links:
| ';">
Am I wrong?
Feb 14th, 2009 at 7:05 am
Hi Philippe,
Yes, you could do that if you like, I think it might get a little cluttered however, so I just use the css margin attribute to keep the links from crowding each other.
Like this;
.tagcloud a { margin:2px 4px 2px 0; }--Matt