Here is what I'm using... It's not perfect yet, but it's pretty close.
PHP Code:
function buildForumTree($forumid = -1, $depth = 0, $collapseDepth = 1)
{
global $vbulletin;
$forumbits = '';
foreach ($vbulletin->forumcache as $forum)
{
$permissions = fetch_permissions($forum['forumid']);
if (
$forum['depth'] != $depth or
$forum['parentid'] != $forumid or (
!($permissions & $vbulletin->bf_ugp_forumpermissions['canviewothers']) and
!$vbulletin->options['showprivateforums']
)
) continue;
$forum['childArray'] = explode(',', $forum['childlist']);
$forum['subforums'] = count($forum['childArray']);
$show['collapsesubforums'] = ($depth == $collapseDepth and $forum['subforums'] > 2);
$childForumBits = ($forum['subforums'] > 2 ?
buildForumTree($forum['forumid'], $depth + 1)
: ''
);
eval('$forumbits .= "' . fetch_template('portal_forumsbit') . '";');
}
return $forumbits;
}
$forumbits = buildForumTree();
portal_forums
HTML Code:
<table width="180" cellspacing="$stylevar[cellspacing]" cellpadding="$stylevar[cellpadding]" border="0" class="tborder">
<tr>
<td class="thead">Forum Tree</td>
</tr>
$forumbits
</table>
portal_forumsbit
HTML Code:
<if condition="$depth == 0">
<tr>
<td class="alt1">
<span class="smallfont">
<if condition="$show['collapsesubforums']">
<a style="float:$stylevar[right]" href="#" onclick="return toggle_collapse('forumtree_$forum[forumid]')">
<img id="collapseimg_forumtree_$forum[forumid]" src="images/buttons/collapse_alt_collapsed.gif" alt="Hide/Show" border="0" />
</a>
<else />
»
</if>
<strong><a href="forumdisplay.php?$session[sessionurl]f=$forum[forumid]">$forum[title]</a></strong>
</span>
<if condition="$show['collapsesubforums']"><div id="collapseobj_forumtree_$forum[forumid]" style="display: none"></if>
$childForumBits
<if condition="$show['collapsesubforums']"></div></if>
</td>
</tr>
<else />
<div class="smallfont" style="margin-left: 10px; margin-top: 8px">
<if condition="$show['collapsesubforums']">
<a style="float:$stylevar[right]; padding-left: -13px" href="#" onclick="return toggle_collapse('forumtree_$forum[forumid]')">
<img id="collapseimg_forumtree_$forum[forumid]" src="images/buttons/collapse_alt_collapsed.gif" alt="Hide/Show" border="0" />
</a>
<else />
»
</if>
<a href="forumdisplay.php?$session[sessionurl]f=$forum[forumid]">$forum[title]</a>
<if condition="$show['collapsesubforums']"><div id="collapseobj_forumtree_$forum[forumid]" style="display: none"></if>
$childForumBits
<if condition="$show['collapsesubforums']"></div></if>
</div>
</if>