Warning: Parameter 3 to mb_videobot() expected to be a reference, value given in /home/wwwjooms/public_html/libraries/joomla/event/dispatcher.php on line 136

How to implement and generate Tag Clouds

Print E-mail

How to generate Tag Clouds?

The idea is to automate the process of Tag Cloud generation as soon as user writes a post or content on a page. It can be divided into two steps:

  1. Generate Tag Clouds from the content.

Ideally, we would like PHP code to extract relevant tags (keywords) from the content. We do not want common words like “is”, “this”, “the” to be keywords. We can set up our own set of rules depending on the requirement.

Sample PHP code:

function generateTagCloud($content){
$minTagLength=5;
$maxTagLength=14;
$baseFont=16;
$returnArray=array();

$content=str_replace("\r\n"," ",$content);
$content=strip_tags($content);
$tagArray=explode(" ",$content);
for($i=0;$i=$minTagLength && $len< =$maxTagLength) {
$returnArray[]=$tag;
}
}
$returnArray=array_count_values($returnArray);
arsort($returnArray);
ksort($returnArray);
return $returnArray;
}
  1. Display Tags according to their occurrence.

After we have all the tags (keywords) we need to display then according their occurrence or presence in the content. In other words, the tag which is present more times in the content will be displayed in bigger fonts as the rest.

Sample PHP code to achieve this is as follows:

function displayTagCloud($tagCloudArray){
$buffer="";
foreach($tagCloudArray as $tags=>$key) {
$font=($baseFont+($key*10));
$font=$font."px";
$buffer.=" $tags ";
}$buffer.="";
return $buffer;
}
Comments (0)add comment

Write comment

security image
Write the displayed characters


busy
 

Subscribe To Our RSS

Stay informed: Please subscribe to our RSS feed to be informed about new Turn Key Web Solution tips, tutorials, special promotions and other goodies.


subscribe for rss feeds

Get Feed Via Email

You can get your feed directly to your email by feedburner. We respect your privacy and will never distribute your email address to anyone.

Contact Us

Joomsnap.com
6 Harbor Way #209
Santa Barbara, CA 93101
Phone: (800)605-4988
Click Here to E-Mail Us