Login  |  Register
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome, Guest. Please login or register.
Did you miss your activation email?

December 09, 2022, 08:26:05 PM

Login with username, password and session length
Members
  • Total Members: 3853
  • Latest: tty456
Stats
  • Total Posts: 193628
  • Total Topics: 21108
  • Online today: 56
  • Online ever: 3540
  • (September 02, 2022, 06:38:54 PM)
Users Online
Users: 0
Guests: 41
Total: 41

Author Topic: [Reguest] Tag Cloud snippet  (Read 73140 times)

0 Members and 1 Guest are viewing this topic.

soMzE

  • Guest
[Reguest] Tag Cloud snippet
« on: February 28, 2007, 11:11:07 AM »
Hello all!

I have recently installed This mod from SMF and my members are really enjoying it  :)

Is it possible to add the Tag Cloud in a block snippit?

My coding skills aren't that great ( none lol ) so i thought i'll ask it here with all the master coders  ;D

« Last Edit: March 01, 2007, 08:35:32 AM by soMzE »

JPDeni

  • Guest
Re: [Reguest] Tag Cloud snippet
« Reply #1 on: February 28, 2007, 11:20:37 AM »
After a few false starts, this is the code that works. Put the following in a php box:

Code: (FOR SMF1.x) [Select]
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;

Code: (For SMF2) [Select]
global $scripturl, $smcFunc;

$result = $smcFunc['db_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 {int:limit}',
array('limit' = 50)
);

$tags = array();
$tags2 = array();

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

$smcFunc['db_free_results']($result);

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;
« Last Edit: September 14, 2011, 08:24:51 AM by IchBin™ »

soMzE

  • Guest
Re: [Reguest] Tag Cloud snippet
« Reply #2 on: February 28, 2007, 11:22:53 AM »
Ahh thank you JPDeni, would be really great if you can do this  ;D

JPDeni

  • Guest
Re: [Reguest] Tag Cloud snippet
« Reply #3 on: February 28, 2007, 11:28:38 AM »
I can't test it out, because I don't have the mod installed, but it looks like you should be able to use the code from the mod in a block.

[bad code removed to prevent confusion]
« Last Edit: March 01, 2007, 08:26:02 AM by JPDeni »

soMzE

  • Guest
Re: [Reguest] Tag Cloud snippet
« Reply #4 on: February 28, 2007, 11:36:47 AM »
I'm sorry, i tried it in a scriptbox, phpbox and htmlbox and it's not working yet :(

With the phpbox i get a parse error:

Code: [Select]
Parse error: syntax error, unexpected $end in /home/..............public_html/forum/Sources/Load.php(1753) : eval()'d code(35) : eval()'d code on line 70
and with the scriptbox you see the whole code appearing..
« Last Edit: February 28, 2007, 11:42:15 AM by soMzE »

JPDeni

  • Guest
Re: [Reguest] Tag Cloud snippet
« Reply #5 on: February 28, 2007, 11:52:06 AM »
It goes into a php box. (I always forget to mention that. Sorry. :) ) Just about everything that I write goes into a php box.

[bad code removed to prevent confusion]

If this doesn't work, I don't know what to say. I can't test it unless I install the mod, and I don't want to install the mod.
« Last Edit: March 01, 2007, 08:25:09 AM by JPDeni »

soMzE

  • Guest
Re: [Reguest] Tag Cloud snippet
« Reply #6 on: February 28, 2007, 12:12:15 PM »
I'm sorry, it isn't working, now the block stays empty.. Is there anything i can do so it's easier for you to see what the problem can be?  :)


JPDeni

  • Guest
Re: [Reguest] Tag Cloud snippet
« Reply #7 on: February 28, 2007, 12:30:52 PM »
I suppose you could give me full admin rights to your site. But not today. I'm going to be offline for the rest of the day.

soMzE

  • Guest
Re: [Reguest] Tag Cloud snippet
« Reply #8 on: February 28, 2007, 03:24:30 PM »
I suppose you could give me full admin rights to your site. But not today. I'm going to be offline for the rest of the day.

Ofcourse, no problem.. please let me know when you have some time to do this :) Thanks again JPDeni :)

JPDeni

  • Guest
Re: [Reguest] Tag Cloud snippet
« Reply #9 on: February 28, 2007, 06:24:45 PM »
My migraine lifted (thank goodness for drugs!), so if you want to set up an account for me where I can access the blocks and the error log on your site, I'll see if I can figure out what the problem is. Send me a private message with a link to your site and the account info.