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

Recent

Welcome to TinyPortal. Please login or sign up.

March 29, 2024, 07:01:52 AM

Login with username, password and session length
Members
Stats
  • Total Posts: 195,106
  • Total Topics: 21,213
  • Online today: 358
  • Online ever: 3,540 (September 03, 2022, 01:38:54 AM)
Users Online
  • Users: 0
  • Guests: 161
  • Total: 161

[Block] Article Category Menu list

Started by IchBin, October 21, 2007, 05:22:59 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

IchBin

This code snippet will grab all the titles of Categories and create a list with sub-categories indented. Thanks to Jaybachatero from SMF for the help.

Add this to a phpbox type block.

global $db_prefix, $scripturl;

$request = db_query("
SELECT id, value1, value2
      FROM {$db_prefix}tp_variables
        WHERE type = 'category'", __FILE__, __LINE__);

$links = array();
while ($row = mysql_fetch_assoc($request))
{
// It's a parent.
if (empty($row['value2']))
$links[$row['id']] = array(
'id' => $row['id'],
'name' => $row['value1'],
'link' => '<a href="' . $scripturl . '?cat=' . $row['id'] . '">' . $row['value1'] . '</a>',
'children' => array()
);
elseif (isset($links[$row['value2']]))
$links[$row['value2']]['children'][$row['id']] = array(
'id' => $row['id'],
'name' => $row['value1'],
'link' => '<a href="' . $scripturl . '?cat=' . $row['id'] . '">' . $row['value1'] . '</a>',
); 
}
mysql_free_result($request);

echo '
<ul style="list-style-type: none; margin-left: 0; padding-left: 0;">';

// Loop through the array.
foreach ($links as $link)
{
if (empty($link['children']))
echo '
<li>', $link['link'], '</li>';
else
{
echo '
<li>', $link['link'], '
';

// Indented Child links
                // Change margin setting for more indentation if needed.
foreach ($link['children'] as $child)
echo '
<li style="margin-left: 7px">', $child['link'], '</li>';

echo '

</li>';
}
}
echo '
</ul>';


Here's an additional nice looking layout and design of this code posted by Stardust.
http://www.tinyportal.net/index.php?topic=19495.msg203123#msg203123

shawnlg

Great I look forward to applying the code.

Shawn Larson

shawnlg

Looks good thank you.

One thing that would be nice to see in the future is the ability to collapse the subcategories in the categories if that makes any sense.  Thanks again for your help!

IchBin

Well, in order to make the categories upshrink that would either require a database setting stored, or a cookie. Of which, I don't really know how to do atm. :(

shawnlg

We will just leave this up and maybe somebody will have a suggestion.  I really need to learn php.  I have lots of cool ideas..

IchBin

Well, doing the upshrink requires javascript. And I know pretty much zero when it comes to javascript.

lebisol

You could reuse the upshrink code that came with default shirink-ers or implement this
http://www.tinyportalmedia.com/main/index.php/topic,1273.0.html
after Drgoon fixes up some details.

IchBin


rockyrails

Thanks - great menu - even when made available only to admins makes it easy to access all the artilcles from the homepage. Thanks again
Cheers

lebisol

Quote from: IchBinâ,,¢ on October 25, 2007, 01:16:49 AM
Feel free to do it lebisol. :)
:) Hey he asked for suggestions ...I will send you a pm if interested.
All the best!