TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,963
  • Latest: BiZaJe
Stats
  • Total Posts: 195,917
  • Total Topics: 21,308
  • Online today: 884
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 1
  • Guests: 210
  • Total: 211
  • @rjen

[Reguest] Tag Cloud snippet

Started by soMzE, February 28, 2007, 06:11:07 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

insanemustang

I love this mod, and by adding the block it could really be a big thing for my site.  I do have 1 question though.

Is there a way to make the font sizes of the tags inside the block random, after all that is the purpose of the "cloud".

I read through the entire thread here, and if I missed it I apologize, but I don't believe I did.

Thanks, great work JPDeni

insanemustang

I apologize, I just realized that when a tag is used twice, the size changes.  This block is complete  O0

sammyto

Hi JPDeni sorry to revive this old post but I wonder if you can do the same with the GoogleTagged Mod... :-\

JPDeni

I don't know. There would be no way for me to test any code that I write even if I installed the mod. People don't use Google to access my test site and I'm not going to install it into my live site.

I don't have a clue about the code that's in this topic, since I haven't looked at it in months. I'll take a look at the code and the mod and see if there's anything the two have in common.

But I wouldn't hold out a lot of hope if I were you.

SteveW

Hi - I have this tag cloud on my website but I cannot get the fonts to change size, they all appear normal size:

my site is http://www.alienexistence.com

JPDeni

For some reason, your font sizes are all the same -- 95%. It could be that all of your tags appear equally on your site. If you want me to debug the code, you'll need to post the code for me to debug.

SteveW

This is the code:

global $db_prefix, $scripturl;
$query = "SELECT t.tag AS tag, l.ID_TAG, COUNT(l.ID_TAG) AS quantity
  FROM {$db_prefix}tags as t, {$db_prefix}tags_log as l WHERE t.ID_TAG = l.ID_TAG
  GROUP BY l.ID_TAG
  ORDER BY l.ID DESC LIMIT 50";

$result = db_query($query, __FILE__, __LINE__);

$tags = array();

$tags2 = array();

while ($row = mysql_fetch_array($result))
{
    $tags[$row['tag']] = $row['quantity'];
    $tags2[$row['tag']] = $row['ID_TAG'];
}

if(count($tags2) > 0)
{
// change these font sizes if you will
$max_size = 250; // max font size in %
$min_size = 95; // min font size in %

// get the 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 (0 == $spread)
{ // we don't want to divide by zero
    $spread = 1;
}

// determine the font-size increment
// this is the increase per tag quantity (times used)
$step = ($max_size - $min_size)/($spread);

// loop through our tag array
$poptags = '';
$row_count = 0;
foreach ($tags as $key => $value)
{
$row_count++;
    // calculate CSS 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 = $min_size + (($value - $min_qty) * $step);
    // uncomment if you want sizes in whole %:
    // $size = ceil($size);

    // you'll need to put the link destination in place of the #
    // (assuming your tag links to some sort of details page)
    $poptags .= '<a href="' . $scripturl . '?action=tags;tagid=' . $tags2[$key] . '" style="font-size: '.$size.'%"';
    // perhaps adjust this title attribute for the things that are tagged
   $poptags .= ' title="'.$value.' things tagged with '.$key.'"';
   $poptags .= '>'.$key.'</a> ';
   if ($row_count > 6)
   {
    $poptags .= '<br />';
    $row_count =0;
   }
}
}
echo "<center>" . $poptags . "</center>";


thankyou

JPDeni

Possibly the person who wrote the code will come by (or you could send him/her a PM). I don't have the mod installed, nor a site where I would be able to test various things to debug. It looks like it should work.

SteveW

Hi JPDeni, I have messed about and your right it does work, when I add a similar tag the font increases. The tags obviously haven't got enough tags to increase the font.

Would it be easy enough to pull random tags rather than the latest tags?

JPDeni

It should work if you change


ORDER BY l.ID DESC LIMIT 50";


to


ORDER BY RAND() LIMIT 50";

This website is proudly hosted on Crocweb Cloud Website Hosting.