defeated Posted August 28, 2009 Share Posted August 28, 2009 Hi, I have the following code making up a tag cloud. I have just realised that it will not be limited... so if I have 1,000 tags they will all show. Any ideas on how to modify it to limit the tags that show to 150? Cheers function tag_cloud() { $min_size = 9; $max_size = 30; $tags = tag_info(); $minimum_count = min(array_values($tags)); $maximum_count = max(array_values($tags)); $spread = $maximum_count - $minimum_count; if($spread == 0) { $spread = 1; } $cloud_html = ''; $cloud_tags = array(); // create an array to hold tag code foreach ($tags as $tag => $count) { $tag_url=str_replace(" ","-",strtolower($tag)); $size = $min_size + ($count - $minimum_count) * ($max_size - $min_size) / $spread; $cloud_tags[] = '<a style="font-size: '. floor($size) . 'px; line-height:'. floor($size+. 'px;' . '" class="tag_cloud" href="http://www.mynextjob.ie/tags/' . $tag_url . '.jobs" title="' . $count . ' job(s) tagged \'' . $tag .'\'">' . htmlspecialchars(stripslashes($tag)) . '</a>'; } $cloud_html = join("\n", $cloud_tags) . "\n"; return $cloud_html; } Quote Link to comment https://forums.phpfreaks.com/topic/172250-solved-help-with-tag-cloud/ Share on other sites More sharing options...
ignace Posted August 28, 2009 Share Posted August 28, 2009 if ($maximum_count > 150) { return ''; } Quote Link to comment https://forums.phpfreaks.com/topic/172250-solved-help-with-tag-cloud/#findComment-908196 Share on other sites More sharing options...
defeated Posted August 28, 2009 Author Share Posted August 28, 2009 No. That didn't work. max_count is the tag with the highest individual count. I sorted it though. Just added ORDER BY count DESC LIMIT 0,150 to my query. Quote Link to comment https://forums.phpfreaks.com/topic/172250-solved-help-with-tag-cloud/#findComment-908212 Share on other sites More sharing options...
ignace Posted August 28, 2009 Share Posted August 28, 2009 ORDER BY count DESC LIMIT 0,150 That would have been my advice if their even were a query in your code example. Quote Link to comment https://forums.phpfreaks.com/topic/172250-solved-help-with-tag-cloud/#findComment-908303 Share on other sites More sharing options...
defeated Posted August 28, 2009 Author Share Posted August 28, 2009 Yep, sorry about that. Quote Link to comment https://forums.phpfreaks.com/topic/172250-solved-help-with-tag-cloud/#findComment-908322 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.