List of topics of a particular bbPress forum

This tutorial will demonstrate the usage of custom queries so as to show topics of a certain bbPress forum along with Topic starter and Last Poster of inside WordPress. 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 id="forumlist">
	<thead>
		<tr>
		<th>Topics</th>
		<th>Author</th>
		<th>Last Reply by</th>
		</tr>
	</thead>
	<tbody>
	<?php
	$forum_id = 7;
	$limit = 5;
	global $wpdb;
	$query = "SELECT topic_title,topic_poster_name,topic_last_poster_name FROM life_topics WHERE forum_id = ".$forum_id." LIMIT ".$limit;
	$topicslist = $wpdb->get_results($query,"ARRAY_N");
	
	if(!$topicslist)
		echo "err";
	else
	{
		foreach( $topicslist as $topicslist )
		{
			echo '<tr>';
			echo '<td>'.$topicslist[0].'</td>';
			echo '<td>'.$topicslist[1].'</td>';
			echo '<td>'.$topicslist[2].'</td>';
			echo '</tr>';					
		}
	}		
	?>					
	</tbody>
</table>
</div>

This is a very basic demonstration of fetching the data in a simple table. You need to change the forum_id to the id of your forums (Look into your database via phpMyAdmin) on line 12, change the no of topics to display on line 13 and change the bbPress table prefix in query on line 15.

You can also make your titles hyperlinked with the topic slug by fetching topic_slug from the database and generating the URL as per your permalinks setup. Doing this goes beyond the scope of this simple tutorial. You can also fetch topic_time to display the time in another column of the table. Just add CSS classes to style the table via CSS.

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.


Comments

16 responses to “List of topics of a particular bbPress forum”

  1. […] Ashfame – List of topics along with Topic starter & Last poster of a particular bbPress f… […]

  2. Hi Ashish, this could be just what I’m looking for. I’ve got a bbPress setup with ten forums for students at different levels. I’d like to be able to have ten WordPress pages, each one showing the topics, posts and topic starter for a particular bbPress forum, so that Module One students can only access the Module One forum and so on, and will still see the WordPress sidebar and widgets.
    Is this possible??? And how would I do it!!!
    Your advice appreciated
    Linda
    PS I have integrated my WordPress 3.0 with bbPress.

  3. Hi Ashfame, I read the post but am not sure how to make it work so that on WP Page 1 visitors will only see the links for bbPress Forum 1, Page 2 visitors will only see the links for bbPress Forum 2 and so on.
    Any idea if this can be done?
    Thanks
    Linda

    1. Hi Linda,

      Yes, you can do that and that’s what I have shown in the example. The forum ID will fetch the details of a particular forum only.

      If all this is technical to you, then you can hire me to do the job.

      Thanks
      Ashfame

  4. Hi Ashfame, I’d be glad to give you a donation if I can get it to work. I’m just a bit confused where you say to put the code in the template. If it goes in the theme’s page template then I don’t see how you can get different pages to show different forum links. I tried just pasting it into the html window of a test page but when I clicked on Preview it was just gobbledegook!
    Your advice appreciated
    Linda

    1. The code needs to be inside WordPress.
      Create a page template and copy paste this php code in it and fill forum is by checking your database.
      Also both WordPress and bbPress needs to be installed in the same database.

    2. Are you also trying to limit the access to other forums or just show the concerned one?
      I think its better that we talk on this via email or IM.
      Sending you an email.

  5. saw steven Avatar
    saw steven

    First of for I am newbie. I wanna try to put wp sidebar on bbpress. I follow your instruction and some other like C_K and some others. Now my wp is 3.1 and bbpress is 1.0.3 are deep integrated. But my side bar is not show at correct position. May I have some advice from you? this is my test site. htpp://itforall.co.cc
    Thanks in advance,

    1. If the sidebar shows up, then its all fine. You need CSS fixes

      1. saw steven Avatar
        saw steven

        Thanks for your reply! Yes I found today! because wp site css take over the container of my side bar. so I couldn’t fix it. Unless I give new div to sidebar and change code to work with bbpress css. Honestly I just learn wp in just 2 week ago and I do not know about css too. That’s is too much for me. ๐Ÿ˜€ . Integration alone cost me 1week sleepless. Is it possible to write own sidebar, then use inject html to that bar? For example I just create plain sidebar, then I call sidebar.php with html code? Thanks you so much for your tutorial too. And pardon me for silly questions.

        1. No problem! If you want widgetized sidebars then just an include won’t work, you need to use a WP sidebar. Does that answer your question?

  6. saw steven Avatar
    saw steven

    PS. Anyway before I get advice from you I’ll try to get a container and try to call get_sidebar. I don’t know work or not…. Thank you so much!

  7. saw steven Avatar
    saw steven

    It works! Thanks! but work the whole day! ๐Ÿ˜€ Thank you! I took one theme with right side bar. Than I delete the whole sidebar code and put get_sidebar within the container. Now its work. Thank you.

  8. saw steven Avatar
    saw steven

    Exactly! As you say it is not work with “include”, use MU side bar then work, I found _C_K plugin that call bb_get_sidebar. I installed it and call with bb_get_sidebar is much better. If not the effect from wp themes is keep disturb the sidebar. I get sidebar from my MU themes. As I mentioned I just put . After that just play with css. It much easier and not much work.
    Thank you so much for your help!!

    1. Good to hear that you got it all sorted out.