A lot of people and businesses use WordPress and, more to the point, a lot of them also use the forums program (plugin) BBPress. So you would think that it would be easy to figure out how to display a list of the newest 3 or 5 or whatever number you like posts at the top of the BBPress forums listings, above the full forum listing. Or that there would be a WordPress plugin that will put the newest BBPRess posts at the top. But there isn’t. So we’re going to tell you how to do it.
Here is what a typical BBPress forums installation looks like – this is from DadsRights.org, another site published by our parent company.
Typical BBPress Forums
But what we wanted (and what you probably want, if you are reading this article) is to have a separate section at the top that lists the newest topics and replies, so that visitors to the forums could instantly see and read the most recently updated or replied-to posts, and the newest topics.
In short, we wanted it to look like this:
BBPress with Newest Posts and Replies Listed at Top
You can see this live, in action, at http://dadsrights.org/forums/.
Here’s how to do it.
How to List Newest Topics, Posts and Replies at the Top of BBPress Forums
First, you have to be comfortable editing source files. This means logging in to your server, and actually getting your hands in, up to your elbows, in code. But odds are if you are looking to do this, you’re already comfortable with that. And even if you aren’t, it’s really not that difficult.
Go to your /wp-content/plugins/bbpress directory.
From there, you are going to want to go to the /templates/default/bbpress directory.
(Yes, there are more than one directory called “bbpress”; the first one is the top level directory for the bbpress plugin, the second is a subdirectory.)
So here is the full path:
Of course, you will replace “YOURDOMAIN” with whatever your domain name is. So if your domain is example.com, for example, your full path would be:
Now, in that /plugins/bbpress/templates/default/bbpress directory, you will find a file called “loop-forums.php”.
The very first thing to do is to make two copies of that file. We usually make one called, for example, loop-forums.original, and then another that is your working backup. This way, if something goes amiss, you will always be able to find the original file.
Now, to modify loop-forums.php so that it will display your newest posts at the top of the BBPress forums:
Edit loop-forums.php, and look for a line that says:
<ul id=”forums-list-<?php bbp_forum_id(); ?>” class=”bbp-forums”>
It should be right around line number 16.
Don’t do anything with that line, but just below that line, insert this:
if ( bbp_has_topics( array( ‘author’ => 0, ‘show_stickies’ => ‘true’, ‘meta_key’ => ‘_bbp_last_active_time’, ‘orderby’ => ‘meta_value’, ‘order’ => ‘DESC’, ‘post_parent’ => ‘any’, ‘posts_per_page’ => 2 ) ) ) bbp_get_template_part( ‘bbpress/loop’, ‘topics’ );
And save the file. Note that where it says:
‘posts_per_page’ => 2
…you can change ‘2’ to whatever number you like. This is the integer that determines how many “newest” listings you have at the top.
That’s all there is to it! If this causes any problems, it’s easy to back out of it by simply copying the loop-forums.original over to loop-forums.php.
You can also edit loop-forums.php to add hard-coded links (such as on the DadsRights.org site where it says “READ ME FIRST: How to Use the Forums and Chat System”), and to include text, such as on DadsRights.org where it says “Newest Conversations in the Fathers’ Rights Forums”.
Let us know if and where you implement this hack!
|Get notified of new Internet Patrol articles!