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

Recent

Welcome to TinyPortal. Please login or sign up.

December 06, 2023, 07:11:13 AM

Login with username, password and session length
Members
Stats
  • Total Posts: 194,611
  • Total Topics: 21,189
  • Online today: 73
  • Online ever: 3,540
  • (September 03, 2022, 01:38:54 AM)
Users Online
Users: 0
Guests: 26
Total: 26

[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.

JPDeni

Well, now don't I feel like a doofus?  :uglystupid2:

After working on your site for a little bit, I found the problem. There was no command to actually print them out.  :2funny:

I've added the right code to your site and edited it here for others to use.

Blame it on the migraine. Yeah, that's it!!  ::)

soMzE

YOUR AWESOME!!!  ;D It looks really cool!! Me so happy now haha, don't know what to say.. my first request here, it's a special day today LOL

And to bad you have these migraines JPDeni, it's not nice.. but still, you're great!  ;D

If others are to use this code, to reduce the number of populair tags change:

ORDER BY l.ID DESC LIMIT 25";

Can't thank you enough!!  :laugh:




JPDeni

LOL! Well, I'm glad I figured it out and I'm glad you are happy with the results. It does look cool.

The migraines aren't fun, to be sure, but I'm used to them. They just sorta get in the way of thinking sometimes.

soMzE

#13
Yes i'm really happy with the results!  :)

One question, when i reduce the number of tags in the snippit, this also affects the main page of Tag Modification, is there a way to only reduce them in the block?  :)

JPDeni

#14
I think it may be because of the variable used. See if this works:

[code moved to second post in topic]

soMzE

That works great!!  ;D Shall i update the first post with this new code JPDeni?

JPDeni

I'll update my posts with the correct code and clean things up a bit for future reference. I'm sure there will be others who will be interested in using this.

whatever

JPDeni:
The code generates a tag cloud just fine, thanks you  8)
A question, please - it is supposed to produce texts of varying size, because it does not do that for me?
Thanks

JPDeni

Yes, it is, if the members have different numbers of posts. If all of them listed have the same number of posts, then the text would all be the same size.

whatever

Then I have a problem, as the members listed have different numbers of posts, yet the font size remains the same.
I am using the code from the second post:
]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 = 100; // 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;id=' . $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 > 5)
   {
    $poptags .= '<br />';
    $row_count =0;
   }
}
}
echo $poptags;