We received this question from a user on our community site. You'll note that we use bbPress to power our forum, and Drupal to power our community site (which you can visit by clicking on the "exit forum" link in the main menu above).
Here's the code we use to get the last 5 bbPress topics to appear in a sidebar block on our Drupal site:
<?php
db_set_active('bbpress');
unset ($output); // clear previous output
$list_no =5;
$sql = "SELECT bb_topics.topic_title, bb_topics.topic_id, bb_topics.topic_slug FROM bb_topics WHERE bb_topics.topic_status = 0 ORDER BY bb_topics.topic_id DESC LIMIT $list_no";
$output .= "<ul>";
$result = db_query($sql);
while ($anode = db_fetch_object($result)) {
$output .= "<li>".l($anode->topic_title, "http://forum.contractwebdevelopment.com/topic/$anode->topic_slug")."</li>";
}
$output .= "</ul>";
print $output;
db_set_active('default');
?>
Note that the key is calling the bbPress database in the first line: db_set_active('bbpress');
To have this work, you'll need to specify two databases in your Drupal's settings.php file, as follows:
$db_url['default'] = 'mysql://user:pw@localhost/db';
$db_url['bbpress'] = 'mysql://user:pw@localhost/db';