Search tags code - help required

Hi,
I wonder if anyone could advice a complete novice? I’m looking to limit the number of tags displayed on my website. As it stands the number is limitless and I’m having to delete the tags everyday in phpmyadmin.

I’ve ran dozens of searches on Google and have tried various snippets of code, all to no avail.

TIA :slight_smile:

[php]// ------------------------------------------------------------------------
;

class Lib_TagClouds
{
function displayTagClouds($tags,$onClick=’’)
{
$res=’’;

	if(!(empty($tags)))

	{



		//ksort($tags);
		
		$max_size = 30; // max font size in pixels
		$min_size = 10; // min font size in pixels
		

		
		// 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));
			
					$res.= '<a href="'.$onClick.$key.'" style="text-decoration:none; font-size: ' . $size . 'px" title="' . $value . ' times searched." >' . $key . '</a> ';
			}
	}
	
	return $res;
}

}
?>

[/php]

The easiest (most brutal) way to do it would simply be to cut the array at a predetermined amount:
[php]array_splice($tags, 5); // show 5[/php]

You could cut it in half:
[php]array_splice($tags, sizeof($tags) / 2); // show half of the current amount.[/php]

You could divide it by x:
[php]array_splice($tags, sizeof($tags) / 4); // show a quarter of the current amount.[/php]

Hope this give you a few tricks to play with.
Red :wink:

Thank you very much! That did the trick. :slight_smile:

no worries, happy to help. :slight_smile:

Like i said, it’s a bit brutal and just chops the array regardless.
If it was me i’d sort the array into most popular then chop the top ten. (or however many you wish)

Red :wink:

Sponsor our Newsletter | Privacy Policy | Terms of Service