cloud(): Tag cloud

Mulder made some code to display a tag cloud in the template.


Here is the code (with some explanation in it) to put in CMS.PHP (functions.php) or better include as an external file and then call in template.htm:

// not part of cmsimple ©mulder - free to use - no support
function cloud(){
// copy in cms.php & call in template with cloud();
global $cf; // cmsimplecontent
$a = array_count_values(preg_split('/\s*[\s+\.|\?|,|(|)|\-+|\'|\"|=|;|×|\$|\/|:|{|}]\s*/i', strtolower(strip_tags(content()))));
$stopwords = array( '', 'a', 'an', 'the', 'and', 'of', 'i', 'to', 'is', 'in', 'with', 'for', 'as', 'that', 'on', 'at', 'this', 'my', 'was', 'our', 'it', 'you', 'we', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '10', 'about', 'after', 'all', 'almost', 'along', 'also', 'amp', 'another', 'any', 'are', 'area', 'around', 'available', 'back', 'be', 'because', 'been', 'being', 'best', 'better', 'big', 'bit', 'both', 'but', 'by', 'c', 'came', 'can', 'capable', 'control', 'could', 'course', 'd', 'dan', 'day', 'decided', 'did', 'didn', 'different', 'div', 'do', 'doesn', 'don', 'down', 'drive', 'e', 'each', 'easily', 'easy', 'edition', 'end', 'enough', 'even', 'every', 'example', 'few', 'find', 'first', 'found', 'from', 'get', 'go', 'going', 'good', 'got', 'gt', 'had', 'hard', 'has', 'have', 'he', 'her', 'here', 'how', 'if', 'into', 'isn', 'just', 'know', 'last', 'left', 'li', 'like', 'little', 'll', 'long', 'look', 'lot', 'lt', 'm', 'made', 'make', 'many', 'mb', 'me', 'menu', 'might', 'mm', 'more', 'most', 'much', 'name', 'nbsp', 'need', 'new', 'no', 'not', 'now', 'number', 'off', 'old', 'one', 'only', 'or', 'original', 'other', 'out', 'over', 'part', 'place', 'point', 'pretty', 'probably', 'problem', 'put', 'quite', 'quot', 'r', 're', 'really', 'results', 'right', 's', 'same', 'saw', 'see', 'set', 'several', 'she', 'sherree', 'should', 'since', 'size', 'small', 'so', 'some', 'something', 'special', 'still', 'stuff', 'such', 'sure', 'system', 't', 'take', 'than', 'their', 'them', 'then', 'there', 'these', 'they', 'thing', 'things', 'think', 'those', 'though', 'through', 'time', 'today', 'together', 'too', 'took', 'two', 'up', 'us', 'use', 'used', 'using', 've', 'very', 'want', 'way', 'well', 'went', 'were', 'what', 'when', 'where', 'which', 'while', 'white', 'who', 'will', 'would', 'your');
foreach ($stopwords as $word) unset( $a[$word] );
// ksort( $a );  //uncomment if you want sort the table result
$out='<p class=cloud>'; // you can set a class in .css called cloud
foreach ($a as $word => $count) {
// make the % size depends of count
 if ($count <= 3) {$size = 75;}
  elseif ($count <= 4) {$size = 100;}
  elseif ($count <= 5) {$size = 125;}
  elseif ($count <= 6) {$size = 150;}
  elseif ($count <= 10) {$size = 175;}
  elseif ($count <= 20) {$size = 200;}
 else $size = 225 ;
// keyword needs to be referenced $count times & have length >2
 if(($count>2)&&(strlen($word)>2)) {$out.='<span style="font-size: ' . $size . '%;"><acronym title="' . $word. ' ' .$count . ' times.">' . $word . '</acronym></span> ';}
return $out.='</p>' ;

back to addons

addons/cloud.txt · Last modified: 2008/02/26 12:33 by gerdx