HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media


Welcome to TinyPortal. Please login or sign up.

June 25, 2024, 10:27:19 AM

Login with username, password and session length
  • Total Posts: 195,280
  • Total Topics: 21,227
  • Online today: 194
  • Online ever: 3,540 (September 03, 2022, 01:38:54 AM)
Users Online
  • Users: 0
  • Guests: 185
  • Total: 185

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


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>',

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>';
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 '

echo '

Here's an additional nice looking layout and design of this code posted by Stardust.


Great I look forward to applying the code.

Shawn Larson


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!


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


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


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


You could reuse the upshrink code that came with default shirink-ers or implement this,1273.0.html
after Drgoon fixes up some details.



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


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!