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

Recent

Welcome to TinyPortal. Please login or sign up.

May 23, 2024, 09:53:20 AM

Login with username, password and session length
Members
Stats
  • Total Posts: 195,197
  • Total Topics: 21,221
  • Online today: 67
  • Online ever: 3,540 (September 03, 2022, 01:38:54 AM)
Users Online
  • Users: 1
  • Guests: 42
  • Total: 43
  • @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.

soMzE

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


JPDeni

#1
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;


soMzE

Ahh thank you JPDeni, would be really great if you can do this  ;D

JPDeni

#3
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]

soMzE

#4
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:

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

JPDeni

#5
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.

soMzE

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

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

Quote from: JPDeni on February 28, 2007, 07: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.

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

JPDeni

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.