A

Show bbPress forum list with posts & topics count in WordPress

This tutorial will demonstrate the usage of custom queries so as to show bbPress forum list inside WordPress. We would like it to display the list of forums along with their topic & post count. Before you can play around with bbPress information, you need to integrate WordPress with bbPress. After integration you can place […]

This tutorial will demonstrate the usage of custom queries so as to show bbPress forum list inside WordPress. We would like it to display the list of forums along with their topic & post count.

Before you can play around with bbPress information, you need to integrate WordPress with bbPress. After integration you can place this code anywhere in your template and it will fetch information from bbPress tables.

<div id="bbpress_forumlist">
    <table>
        <thead>
            <tr>
                <th>Forums</th>
                <th>Topics</th>
                <th>Posts</th>
            </tr>
        </thead>
        <tbody>
        <?php
        global $wpdb;
        $forumslist = $wpdb->get_results("SELECT forum_name, topics, posts from bb_forums","ARRAY_N");
        if ($forumslist)
        {
            foreach ($forumslist as $row)
            {
                echo '<tr>';
                echo '<td>'.$row[0].'</td>';
                echo '<td>'.$row[1].'</td>';
                echo '<td>'.$row[1].'</td>';
                echo '</tr>';
            }
        }
        else
            echo 'Error fetching data';
        ?>
        </tbody>
    </table>
</div>

You can easily style the table via CSS. Just add some classes and you can give it the look you want. If you have a different bbPress table prefix, make sure you change the table name in the SQL query (13th line). There is more that you can do with this actually. Fetch more things like forum description, forum slug or make the forum name clickable to the forum page of bbPress. Take a quick peek at NAP's homepage and you will get an idea.

Have anything to ask or more to implement. Feel free to ask in the comments! Make sure you check out other tutorials to show bbPress content inside WordPress & the whole WordPress as CMS series.

3 responses to “Show bbPress forum list with posts & topics count in WordPress”

  1. […] List of forums with topic & post count […]

  2. Rodrigo says:

    You said it was able to add link to the titles, how do you go about that? and also how do I make it so I only show recent or a number of them instead of all of them?

    • Ashfame says:

      Yes!
      The tutorial is pretty basic for developers to give an idea of how it can be done. What you want to accomplish is a little complex actually.

      You can do that by fetching forum_slug too and then print html output for a link and generate the link as per your permalink and you can limit that by specifying LIMIT in mysql query.

      Doing it for a specific site will be easier as compared to doing it for a generalized site which take care of site settings by itself.