This is not the best way to do it in terms of performance and efficiency, but it is the way of minimal changes to Marc’s version.
So if anyone wants to do it like I do (predefining the words which can appear in the cloud, instead of creating a huge exclude-list)
here’s the code:
/****************************************************<?
* Name: TagcloudInc
* Version 1.0
* Desc: Displays how frequently the members of a wordlist appear in the site's content as a "tag cloud"
* created by Paul Paulousek [email protected]
* date July, 12. 2006
* based on Tagcloud of Marc Hinse, [email protected], www.modxcms.de
* Version: 1.1.
*
* Usage: [[tagcloudinc?parent=`1,3,5,6,7,14`&min=`3`&landing=`12`]]
* Parameters:
* parent: comma separated list of the folders that contain the documents which are to be counted
* min: Minimum occurrences of a word to be displayed
* landing: the id of your search result page. If you don¥t have one, create it like: [!FlexSearchForm?FSF_showResults=`1` &FSF_showForm=`0`!]
* (this is required for linking the tags)
* ***************************************************/
$parent = isset($parent)? $parent : "0";
$min = isset($min)? $min : "2";
$landing = isset($landing)? $landing : "[~[*id*]~]";
$include = array('blog','method','edit','content','design','links','quickedit','MODx','customize'); //include list (sample, put in your words here)
$zeichen = array(',','.',':'); //array of chars to be deleted
if (strpos($parent,',')){
$parent= explode(',',$parent);
}
$table = $modx->getFullTableName("site_content");
foreach ($parent as $daddy){
$select = $modx->db->select("pagetitle,content,introtext", $table, "parent = $daddy"); // record: title, content, introtext
while ($contents = $modx->db->getRow($select)) {
$content.=$contents['content'].' '.$contents['introtext'].' '.$contents['pagetitle']; //put them together
}
}
$output='<div class="tagcloud">';
$content=strtolower(str_replace($zeichen,'',$modx->stripTags($content))); //all to lower and without HTML
$array_content=explode(' ',$content); //split them in separate words
$anzahl=array_count_values($array_content); //count the words
$words=array();
foreach($anzahl as $key => $wert) {
if($wert>$min && (in_array($key,$include))) { //look if the word counts the required minimum and is in the include list
$words[$key] = $wert; //put them in a new array
}
}
//unset($words['modx']); //if you want to override the value of words (in this case 'modx'), uncomment it and put in your word
$max_size=max($words); //word with most hits
//$words['modx']=8; // put in again your deleted word and value from two lines above
ksort($words); //sort them alphabetically (just comment that out, then they will be unsortet
$multiplier=300/$max_size; //define the multiplier for the size (play with that to fit your site!)
$min_size=30; //minimum size
foreach($words as $key => $wert) {
$font_size=$multiplier*$wert;
//$countvalues='('.$wert.')'; //uncomment this for displaying the hits next to the links
$output.='<span><a style="font-size:'.max($font_size,$min_size).'%;" href="[~'.$landing.'~]&FSF_search='.$key.'">'.$key.'</a>'.$countvalues.'</span> ';
$output.="\r\n";
}
$output.='</div>';
return $output;
Have fun, and thanks Marc for the original!