Info
- 5 posts
- 4 voices
- Started 2 years ago by Adam Harley
- Latest reply from Yukon Cornelius
- This topic is not a support question
Nested topic list code snippet
-
- Posted 2 years ago #
I figure someone might find this useful, as it took me a while to do properly. The following is some code I'm using to create a bullet point (
<ul>) list of forums which nests sub-forums nicely, in my case for a sidebar.<?php if ( bb_forums() ) : while ( $depth = bb_forum() ) : if( $depth > $last_depth ) : ?> <?php echo str_repeat(" ",$depth) ?><ul> <?php else : ?></li> <?php while( $depth < $last_depth ) : echo str_repeat(" ",$depth+1) ?></ul> <?php echo str_repeat(" ",$depth) ?></li> <?php $last_depth--; endwhile; endif; if (bb_get_forum_is_category()) : echo str_repeat(" ",$depth) ?><li class="forum_cat"><a href="<?php forum_link() ?>" title="<?php forum_description(array('before'=>'','after'=>'')) ?>"><?php forum_name() ?></a><?php else : echo str_repeat(" ",$depth+1) ?><li class="forum_subforum"><a href="<?php forum_link() ?>" title="<?php forum_description(array('before'=>'','after'=>'')) ?>"><?php forum_name() ?></a><?php endif; $last_depth = $depth; endwhile ?></li> </ul> </li> </ul> <?php endif; // bb_forums() ?>It should give you reasonably clean indenting of HTML too and is XHTML 1.0 valid. Take out the str_repeat() calls if you don't care about tidy code.
-
- Posted 2 years ago #
Could you show us an example of how this works?
-
- Posted 2 years ago #
Sure.
Some example output
<ul> <li class="forum_subforum"><a href="http://www.foo.bar/forums/forum/ideas-comments" title="">Ideas & Comments</a> <ul> <li class="forum_cat"><a href="http://www.foo.bar/forums/forum/questions" title="">Questions</a> <ul> <li class="forum_subforum"><a href="http://www.foo.bar/forums/forum/metsoc" title="">Meetings / Socials</a></li> </ul> </li> </ul> </li> <li class="forum_subforum"><a href="http://www.foo.bar/forums/forum/tips-amp-tricks" title="">Tips & Tricks</a> <ul> <li class="forum_subforum"><a href="http://www.foo.bar/forums/forum/gigs" title="Music, bands, all that...">Gigs</a> <ul> <li class="forum_cat"><a href="http://www.foo.bar/forums/forum/everything-else" title="">Everything else</a></li> </ul> </li> <li class="forum_subforum"><a href="http://www.foo.bar/forums/forum/sports" title="">Sports</a></li> <li class="forum_subforum"><a href="http://www.foo.bar/forums/forum/minutes" title="">Minutes</a></li> </ul> </li> </ul>In a sidebar, styled with CSS: http://img27.imageshack.us/img27/385/capturecr.png
-
- Posted 2 years ago #
Can someone simplify this code?
1. to show only the parent forums
-
- Posted 1 year ago #
@gerikg did you figure out how to show just the parent categories, and then the sub-categories on a separate page?
thanks,
J
-
You must log in to post.