Dropdown menu with all forums – How to ?
-
Hello!
I’m trying to display a dropdown menu with all the forums on all templates of bbPress. I was able to easily to it on the “content-archive-forum.php” template with this code :
<?php if ( bbp_has_forums() ) : ?> <?php while ( bbp_forums() ) : bbp_the_forum(); ?> <li><a id="textdropdown" class="bbp-forum-title" href="<?php bbp_forum_permalink(); ?>"><?php bbp_forum_title(); ?></a></li> <?php endwhile; ?> <?php else : ?> <?php bbp_get_template_part( 'feedback', 'no-forums' ); ?> <?php endif; ?>
The problem i’m having is on all other pages. I know that it’s passing the wrong forum_id to the bbp_has_forums function but i’m unable to modify the parameters or make a custom function to display a list (with links) of the MAIN forums (the one displayed on the “content-archive-forum.php”).
Basically, it displays the message “Oh bother! No forums were found here!” on all other pages.
Can anyone help me or tell me how to do this ?
Thanks in advance!
-
Please anyone help us, I need the same function…
The problem i’m having is on all other pages
so you altered code in “content-archive-forum.php”
how or what are you doing for the other ‘pages’?
@blackjak231 i think you should make a widget, the forum list widget does list all the forums in links all you would have to do is alter how it is displayed.
And also since it is a widget it should work on all pages in your site.
Thanks for the tip but i actually ended up adding the following at the top of the pages i needed it on :
$args = array( 'post_parent' => 0, );
Not very DRY as it is repeated (i could have done a function though…) but it does the job perfectly.
HOWEVER, since every loop resets the $args array, i think it only works for me because my dropdown menu with the forums is before any other loop on the page.Here is the code i added in the pages i needed to show the dropdown (bootstrap):
<?php if ( bbp_has_forums($args) ) : ?> <?php while ( bbp_forums() ) : bbp_the_forum(); ?> <li><a id="textdropdown" class="bbp-forum-title" href="<?php bbp_forum_permalink(); ?>"><?php bbp_forum_title(); ?></a></li> <?php endwhile; ?> <?php else : ?> <?php bbp_get_template_part( 'feedback', 'no-forums' ); ?> <?php endif; ?>
I hope this helps you @selenii and anybody else who was trying to do this. I would however recommend Robkk’s way as it uses clean code from bbPress. Haven’t tried it though.
Good luck and thank you!
can you show and tell me how you make your menu, please?
Here is a functions / snippet code version for anyone else looking:
—function my_forums_dropdown_shortcode() { // Start buffering output ob_start(); // Dropdown container echo '<select id="forums-dropdown" onchange="location = this.value;">'; // Forum loop if ( bbp_has_forums() ) : while ( bbp_forums() ) : bbp_the_forum(); $forum_permalink = bbp_get_forum_permalink(); $forum_title = bbp_get_forum_title(); echo "<option value='{$forum_permalink}'>{$forum_title}</option>"; endwhile; else : // No forums found bbp_get_template_part( 'feedback', 'no-forums' ); endif; // Close the dropdown echo '</select>'; // Return the buffer contents return ob_get_clean(); } add_shortcode('forums_dropdown', 'my_forums_dropdown_shortcode');
Just paste in [forums_dropdown] where you want output.
- You must be logged in to reply to this topic.