List of topics of a particular bbPress forum
November 14th, 2009 | Tagged as: bbpress ¤ CMS ¤ wordpressIf you are new here. You may want to sign up for e-mail updates or subscribe to my RSS feeds. Thanks for visiting!
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.



Howdy! My name is Ashish K Saini aka Ashfame.

{ 1 Comment }