And you can just keep making it fancier and fancier.
Let’s say you want to also show how many posts each topic has.
echo "<li><a href='/forums/topic.php?id=".$result->topic_id."'>".$result->topic_title."</a> (".$result->topic_posts." posts)</li>";
or how old the last reply is
echo "<li><a href='/forums/topic.php?id=".$result->topic_id."'>".$result->topic_title."</a> (".human_time_diff(strtotime($result->topic_time." GMT"))." ago)</li>";
Let’s put that all together – this should work right inside any wordpress template:
<h2>Latest Forum Discussions</h2>
<ul>
<?php
global $wpdb;
$query="SELECT * FROM bb_topics WHERE topic_status=0 ORDER BY topic_time DESC LIMIT 10";
$results=$wpdb->get_results($query);
foreach ($results as $result) {
echo "<li><a href='/forums/topic.php?id=".$result->topic_id."'>".$result->topic_title."</a></li>";
}
?>
</ul>
So we have the $results, how do we make a pretty list of them, say inside of our sidebar?
We have to loop through them and print them out. This is where that list of fields inside of bb_topics comes in handy.
Here’s just a list of titles to start with:
foreach ($results as $result) {
echo "<li>".$result->topic_title."</li>";
}
Of course that’s not very useful, because they aren’t clickable. To make them clickable will take a little bit more work:
foreach ($results as $result) {
echo "<li><a href='/forums/topic.php?id=".$result->topic_id."'>".$result->topic_title."</a></li>";
}
That example uses quite a few shortcuts to get the job done, it hardcoded the path to your forums (change /forums/ if needed) and even if your bbPress uses pretty permalinks, it simply uses the topic id number to get there – bbPress will redirect back to permalinks. If you absolutely know you have permalinks and want to use them, you could have done something like this instead:
<a href='/forums/topic/".$result->topic_slug."'>"
Now we need to put together a correct mysql query.
Let’s try something simple.
SELECT * FROM bb_topics WHERE topic_status=0 ORDER BY topic_time DESC LIMIT 10
SELECT means “grab the following”
the asterisk means “all the fields in the table”
FROM bb_topics is kinda obvious, it’s the table we want
topic_status=0 means it’s topics not deleted
ORDER BY topic_time DESC means put the newest topics on top
LIMIT 10 means we want only the first 10
Let’s say we also wanted to exclude topics that were closed, since people can’t reply, we don’t want to tease them. In that case you would change the
WHERE topic_status=0
to
WHERE topic_status=0 AND topic_open=1
or let’s say you only wanted “stickies”
WHERE topic_status=0 AND topic_sticky!=0
Okay now to use that in WordPress we do the following:
global $wpdb;
$query="SELECT * FROM bb_topics WHERE topic_status=0 ORDER BY topic_time DESC LIMIT 10";
$results=$wpdb->get_results($query);
If all goes well, WordPress will then execute the query and then fill $results with the answers.
Now comes the output part.
Both bbPress and WordPress have a very simple way of fetching data.
WordPress uses $wpdb
bbPress uses $bbdb
(the db part means database, very simple)
Then there’s the good old “get_results”. They both use that.
bbpress:
$results=$bbdb->get_results("mysql query goes here");
wordpress:
$results=$wpdb->get_results("mysql query goes here");
Many times you can use the same query in either bbpress or wordpress by just changing $bbdb to $wpdb or visa-versa.
Then you have to figure out what you are asking for.
Let’s use the really simple bbPress Topics table as an example. Unless you’ve customized your install, the Topics table is probably called bb_topics
Here are all the fields available inside of bb_topics.
topic_id
topic_title
topic_slug
topic_poster
topic_poster_name
topic_last_poster
topic_last_poster_name
topic_start_time
topic_time
forum_id
topic_status
topic_open
topic_last_post_id
topic_sticky
topic_posts
tag_count
I’m not sure if this has been addressed elsewhere already or a plugin already exists but for novices that have even just a beginner’s knowledge of how php+mysql works I want to show you how easy it is to show bbPress info inside of WordPress and vise-versa.
You should NOT be using overly complex plugins like bbPress-Live or parsing RSS feeds if you have WordPress and bbPress sharing the same database but different tables. Instead, it’s a piece-of-cake to grab info from each other directly and display it. You don’t even need a plugin, you can code it right into your templates (as long as you know they will remain working together).
So I’ll give some examples here and then if anyone has questions feel free to ask.
Did you already figure this out?
They look very well matched.
Are they simply trying to make a link to their forum from their blog and just mask the url so it looks like it’s a page of WordPress?
Just install the forums in /forums/ and make a link from WordPress’s link administration.
WordPress is good for a few authors <-> many commenters, with high quality authors.
bbPress is good for many authors <-> many commenters.
If you want *everyone* to have their own blogs then you want wpmu.
If you want your own social network then you probably want to wait a tiny bit longer for buddypress.
To get bbPress you work you might be able to go into bb_config.php and edit this line
$bb_table_prefix = 'bb_';
and make it say
$bb_table_prefix = '';
(that’s just two single quotes together with no space)
Not sure if it would work and it’s bad idea to keep running like that.
Using phpMyAdmin, you could try to rename all the tables to bb_users, bb_usermeta, etc.
But do you see your WordPress tables? You have a bigger problem is there’s wp_users and wp_usermeta and then you don’t see topics forums posts tables.
You may have installed bbpress into a new database instead of the old wp database?
Copy all the names of the tables in the left hand site of phpmyadmin here so we can see better what’s wrong.
I have an idea for a simple site, but I’m driving myself nuts deciding between bbPress and WordPress. On the front page of the site, I want to be able to add my own content, but also allow readers to post their own experiences and stories. I then want other users to be able to comment on those stories, and rate them. Simple idea, been done before.
Is this better done with WordPress, following this example:
http://creativebriefing.com/how-to-use-wordpress-to-build-a-website-with-user-generated-content/
or WordPress and TDO Mini Forms
or bbPress with a customized front page?
thanks for any insight.
Michael
2.6.5 just replaced a couple files, none related to cookies, so I would guess that 2.6.5 is still compatible with Alpha. The issue with integration was related to the cookie change WordPress made with 2.5 and again in 2.6.
What breaks it is the inclusion of the wordpress functions in the bb-config.php file. If you delete that code and visit the admin, it will work just fine.
Hi there! I am looking for a theme that I could easily edit to make it look like WordPress Revolution Church Theme (http://www.revolutiontwo.com/themes/church). Does anyone know of a theme?
Yes, using those functions will bring the header and footer over. Whether or not they look like you want is up to you to decide. The functions will work, but your bbPress template needs to be setup to display the WordPress header/footer/sidebar properly.
Chrishajer, whats going on. I’m attempting to get my bbpress theme to look like my wordpress theme. I’ve done what you said above (my-templates folder with the kakumei theme). Now what do I need to do? Do I need to use wordpress functions (then get_header & get footer)?
Thanks
Antonio
Hey everyone, hows it going. I’m trying to find out how to match my current wp theme to my bbpress theme. How can I accomplish this?
Thanks
Heres my wp installation
http://kauaihypnosis.site90.com/
and bbpress
http://kauaihypnosis.site90.com/bbpress
Yah the site was still up and running that whole time. I not-so-intelligently generated the sitemap at 11 pm, when it still has a decent amount of traffic.
Personally, I would use the WordPress SiteMap generator but not the bbPress one. Or at least, use the bbPress one only until you notice that it’s starting to slow down the posting process…
> – adding a banner to bbpress like that of my WP
Not sure what you mean there. If it’s navigation you need, you probably want integration with WordPress so you can use the WordPress functions like get_header and get_sidebar. If you mean just a banner ad of some sort, you can just add that to the template file header.php
> – changing the logo (I know, this should be simple)
It is. Just look in header.php for the header div, and style.css for the corresponding css.
> – containing bb within the main area of my WP pages
Not so easy. It doesn’t work well (or at all) in a WordPress page. It’s not a plugin for WordPress, it’s a standalone forum. If you want it to look like a WordPress page, you probably want integration as explained in item one above, or here.
> – adding a navigation button to return to my WP pages
> from bb
Also easy, like changing the logo. You can do it in header.php if you want the link up top. Or you can edit another template file if you want the link somewhere else.
@_ck_: Yah I couldn’t agree more that this would ideally be done with a cron.
@chrishajer: The Google XML Sitemap isn’t done in realtime (unless you set it to do that), but it sure can take a long time! I have 14,804 pages in our WordPress blog and according to the admin logs, the last SiteMap “building process took about 7893.94 seconds to complete and used 44.5 MB of memory.” That’s 13+ minutes!
You probably have the path to the wp-blog-header.php wrong. You can try the full path there in the bb-config.php or you can verify that the relative path is actually correct. You may need to do something like ../wordpress/wp-blog-header.php if your WordPress installation is in a folder on the same level as bbpress. It’s easy to figure out if you have a command line. If not, if you can describe your directory structure, someone can help you with the path to wp-blog-header.php.
I turned that plugin off long ago as well (but sometimes run it manually), because as the forum grew, it was taking longer and longer to regenerate the sitemap, as the visitor waited, as _ck_ said. The Google XML Sitemap plugin for WordPress doesn’t have that problem, but I have no idea what makes it different.
bbPress attempted to correct where it could some of the naming and placement issues for files and functions that persisted in WordPress because of legacy reasons. In that way and a few others it’s design is subtly superior to WordPress.
“Fatal error: Call to undefined function get_forums() in public_html/bbpress/index.php on line 11”
I am new to bbPress and new to WP as well…was trying to integrate WP and bbPress. After integration everything seemed to work perfectly, than I tried to follow this…
“Functions
bbPress will not have access to WordPress’ functions unless you manually tell bbPress to load WordPress first. In order to do that, you need to put require_once(‘path/to/wp-blog-header.php’); in bbPress’ bb-config.php (wp-blog-header is in the same directory as WordPress’ wp-config.php file).
Doing this will add quite a lot of weight to your bbPress installation as it will cause WordPress to load in it’s entirety. Your best option is to try to emulate the functionality you require inside a bbPress plugin.”
Putting:
“require_once(‘../wp-blog-header.php’)
but the Fatal Error occurred.
Any suggestions?
Thanks
It may be a little thing, but I don’t understand why the themes and plugin folders have different names (and are stored in different places) from the similar folders in WordPress.