SimplePortal
Customization => Custom Coding => Topic started by: stikkki on January 10, 2009, 01:57:18 PM
-
there is a mod for SMF for creating tags -
Tagging System For Topics http://www.simplemachines.org/community/index.php?topic=135761.0
Does anyone know a way of adding these tags into a block so that the tags cloud can be displayed on the portal so that the tags are clickable to direct you to the topics
cheers
-
For SMF 1.x:
global $db_prefix, $modSettings, $context, $scripturl;
$result = 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 " . $modSettings['smftags_set_cloud_tags_to_show'], __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)
{
$max_size = $modSettings['smftags_set_cloud_max_font_size_precent']; // max font size in %
$min_size = $modSettings['smftags_set_cloud_min_font_size_precent']; // min font size in %
$max_qty = max(array_values($tags));
$min_qty = min(array_values($tags));
$spread = $max_qty - $min_qty;
if (0 == $spread)
{ // we don't want to divide by zero
$spread = 1;
}
$step = ($max_size - $min_size)/($spread);
$context['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)
$context['poptags'] .= '<a href="' . $scripturl . '?action=tags;tagid=' . $tags2[$key] . '" style="font-size: '.$size.'%"';
// perhaps adjust this title attribute for the things that are tagged
$context['poptags'] .= ' title="'.$value.' things tagged with '.$key.'"';
$context['poptags'] .= '>'.$key.'</a> ';
if ($row_count > $modSettings['smftags_set_cloud_tags_per_row'])
{
$context['poptags'] .= '<br />';
$row_count =0;
}
// notice the space at the end of the link
}
}
echo $context['poptags'];
For SMF 2.x:
global $smcFunc, $scripturl, $modSettings, $context;
$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 " . $modSettings['smftags_set_cloud_tags_to_show']);
$tags = array();
$tags2 = array();
while ($row = $smcFunc['db_fetch_assoc']($result))
{
$tags[$row['tag']] = $row['quantity'];
$tags2[$row['tag']] = $row['ID_TAG'];
}
if (count($tags2) > 0)
{
$max_size = $modSettings['smftags_set_cloud_max_font_size_precent']; // max font size in %
$min_size = $modSettings['smftags_set_cloud_min_font_size_precent']; // min font size in %
$max_qty = max(array_values($tags));
$min_qty = min(array_values($tags));
$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
$context['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)
$context['poptags'] .= '<a href="' . $scripturl . '?action=tags;tagid=' . $tags2[$key] . '" style="font-size: '.$size.'%"';
// perhaps adjust this title attribute for the things that are tagged
$context['poptags'] .= ' title="'.$value.' things tagged with '.$key.'"';
$context['poptags'] .= '>'.$key.'</a> ';
if ($row_count > ($modSettings['smftags_set_cloud_tags_per_row']-1))
{
$context['poptags'] .= '<br />';
$row_count =0;
}
// notice the space at the end of the link
}
}
echo $context['poptags'];
-
Hola. Una cosilla, porque al ingresar eso en un bloque PHP de SimplePortal me marca este error:
Error en la Base de Datos
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 5
Archivo: /homepages/38/d283347434/htdocs/darken/foro/Sources/PortalBlocks.php(3444) : eval()'d code
LĂnea: 7
SMF: 1.1.11
SP: 2.3.2
-
DaRKeN,
Please use the relevant International Support (http://simpleportal.net/index.php?board=38.0) board.
-
OMG! No me di cuenta, lo siento y muchas gracias por tu paciencia y respuesta. :)
-
This is an English only support board. Please use English or use the relevant International Support (http://simpleportal.net/index.php?board=38.0) board.
You will not receive support in a language other than English here.
-
Nathaniel, he just said "OMG! I did not realize this. I'm sorry and thank you very much for your patience and response."
-
Nathaniel, he just said "OMG! I did not realize this. I'm sorry and thank you very much for your patience and response."
Thanks for the translation ccb. :) Its a bit hard to tell when its in a language I don't know though. ;)
-
Yeah I figured. Hope he finds the right support.
-
Why when I click on any tag in tag list, takes me to the my forum page.
Can lead to a topic that contain that word?
I use smf 2 and simple portal 2.3.2.
global $smcFunc, $scripturl, $modSettings, $context;
$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 " . $modSettings['smftags_set_cloud_tags_to_show']);
$tags = array();
$tags2 = array();
while ($row = $smcFunc['db_fetch_assoc']($result))
{
$tags[$row['tag']] = $row['quantity'];
$tags2[$row['tag']] = $row['ID_TAG'];
}
if (count($tags2) > 0)
{
$max_size = $modSettings['smftags_set_cloud_max_font_size_precent']; // max font size in %
$min_size = $modSettings['smftags_set_cloud_min_font_size_precent']; // min font size in %
$max_qty = max(array_values($tags));
$min_qty = min(array_values($tags));
$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
$context['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)
$context['poptags'] .= '<a href="' . $scripturl . '?action=tags;tagid=' . $tags2[$key] . '" style="font-size: '.$size.'%"';
// perhaps adjust this title attribute for the things that are tagged
$context['poptags'] .= ' title="'.$value.' things tagged with '.$key.'"';
$context['poptags'] .= '>'.$key.'</a> ';
if ($row_count > ($modSettings['smftags_set_cloud_tags_per_row']-1))
{
$context['poptags'] .= '<br />';
$row_count =0;
}
// notice the space at the end of the link
}
}
echo $context['poptags'];
-
Nathaniel, he just said "OMG! I did not realize this. I'm sorry and thank you very much for your patience and response."
Thanks for the translation ccb. :) Its a bit hard to tell when its in a language I don't know though. ;)
http://translate.google.com will be helpful! I use it alow for one of my friends is learning japanese and I have a japanese board on my website, I use google translate to communicate, and he understands.
-
For SMF 1.x:
(snip: exactly what I was looking for)
Thank you SO MUCH. May a thousand affectionate hedgehogs descend upon your domicile bearing gifts of gold and chocolate.
-jc