How to create a forums list in bbPress
While redesigning the Theme Hybrid support and community forums, I needed an easy way to show off the list of forums with links to the RSS feeds and number of posts next to each forum name.
What I’ll be showing you in this tutorial is a simple way to do this.
I prefer to have the list of forums in the sidebar while showing the most recent posts in the content area. But, you can use this code in any of your template files for use anywhere on your forums.
The code
What we’ll be doing is using the get_forums()
function to grab an array of all of your forums. Then, we’ll loop through the array, listing a link to each forum, showing the number of posts, and linking to the RSS feed.
<div class="forums-list">
<h3>Forums</h3>
<ul>
<?php $forums = get_forums(); ?>
<?php foreach ( $forums as $forum ) : ?>
<li>
<a class="forum-link" href="<?php forum_link( $forum->forum_id ); ?>"><?php forum_name( $forum->forum_id ); ?></a>
<span class="forum-posts">(<?php forum_posts( $forum->forum_id ); ?> posts)</span>
<a class="rss-link" href="<?php bb_forum_posts_rss_link( $forum->forum_id ); ?>">(<abbr title="Really Simple Syndication">RSS</abbr>)</a>
</li>
<?php endforeach; ?>
</ul>
</div>
The finished product
I worked a little extra CSS magic on mine and came up with this:
I hope you have fun with this code and come up with more unique ways to show off your forums. I provided a few CSS classes to help you out if you want to add your own style. Here they are for reference:
/* Containing <div> */
.forums-list {}
/* Header */
.forums-list h3 {}
/* List */
.forums-list ul {}
.forums-list li {}
/* Forum link */
a.forum-link {}
/* Number of forum posts */
span.forum-posts {}
/* Forum RSS Link */
a.rss-link {}
More bbPress tutorials and discussion to come
I’m not really sure how many folks are using bbPress these days, but it’s the forum software of choice for me. It’s simple and lightweight — everything I need in forum software. I hope that I can bring more people to this platform and do my part in helping the bbPress community grow.
I also hope to continue writing more tutorials like this one, so there’ll be more documentation out there. If you have ideas for tutorials, I’ll see if I can squeeze them in sometime.