Have you ever wanted to display related posts or topics in bbPress like the way you show them in WordPress posts and pages? bbPress is technically the best WordPress plugin to add forum functionality to your WordPress website. However, this plugin does not show any related posts or topics by default. In this article, you will learn how to show related topics in bbPress without any plugin.
Watch this video on how to display related posts or topics in bbPress
Create forums with bbPress
bbPress is the best WordPress plugin to add forum functionality to your website. Even wordpress.org is using bbPress to create an active community and support WordPress users with forums. If you need to run forums on your website to create an active and inviting community, we highly recommend you install bbPress WordPress plugin.
Why display related posts in bbPress topics?
One of the problems with bbPress is that it has not been updated for around two years. In fact, this plugin has a minimalistic design, and you need to install some additional WordPress plugins to extend its functionality, such as related posts or topics. However, any added plugin can slow down your WordPress website, and therefore, it’s not logical to install so many plugins.
At LELB Society, which is a bilingual academy of English and Persian with over 220 registered students and members, it is important for us to display related posts or topics in our forums. This is because asynchronous learning and supporting our students 24/7 are among our main services.
Research has proved that displaying related posts in any WordPress custom post type, such as posts, pages, bbPress topics, etc. can increase user engagement and pageviews. As a result, you can significantly improve the SEO ranking of your website. In this way, your users can stay longer on your website and potentially become your customers or subscribers.
PHP Code to display related posts in bbPress
The following php code is completely optimized and ready to be used. This code will query and fetch 5 related topics that are automatically selected according to the topic tags that exist in any topic. Therefore, for this php code to function properly, first you need to enable topic tags in bbPress. To enable topic tags, in your WordPress dashboard area, go to Settings, Forums, and in the Topic tags section, select Allow topics to have tags.
function aa_related_topics() {
$topic_id = bbp_get_topic_id();
$tags = wp_get_post_terms( $topic_id, bbp_get_topic_tag_tax_id(), array( 'fields' => 'ids' ) );
$args = array(
'post__not_in' => array($topic_id),
'post_type' => bbp_get_topic_post_type(),
'posts_per_page' => 5,
'orderby' => 'DESC',
'tax_query' => array(
array(
'taxonomy' => bbp_get_topic_tag_tax_id(),
'terms' => $tags,
),
),
);
$my_query = new wp_query( $args );
if( $my_query->have_posts() ) {
echo '<div id="related"><h2>Related Topics in Forums</h2>';
while( $my_query->have_posts() ) {
$my_query->the_post(); ?>
<div>
<h3><a href="<?php the_permalink()?>" title="<?php the_title(); ?>"><p><?php the_title(); ?></p><?php the_post_thumbnail(); ?></a></h3>
<p><?php the_time('M j, Y') ?></p>
</div>
<?php }
wp_reset_postdata();
echo '</div>';
}
}
add_action( 'bbp_template_after_single_topic', 'aa_related_topics' );
Topic tags for forums act like tags for posts, and they can come in handy especially when you have a great number of topics and you need to organize them. You can also read this article to show related posts in WordPress posts without any plugin.
Where to put the above php code?
Contrary to popular belief, you don’t need to add this code to your functions.php file. This is because you don’t need to run this code on any page or post. A more rational solution would be to add this code to the end of the template.php file of bbPress topics which is retrievable in the following path when you go to Plugins, Plugin File Editor in your WordPress dashboard area, and select bbPress from the Select plugin to edit drop-down menu on the top-right corner of your screen:
Editing bbpress/includes/topics/template.php (active)
Please note that any imperfection in your plugins or theme files could lead to fatal errors. So, it’s wise to create a backup of your site before editing these files.
How to tweak the php code to display related posts?
The following are some changes you could make to the php code in order to optimize or personalize it the way you like it to be:
- ‘posts_per_page’ => 5, = to modify the number of related posts or topics in forums
- ‘orderby’ => ‘DESC’, = to set descending order to display related posts in bbPress or choose “ASC” for ascending order or “rand” for random selection
- echo ‘<div id=”related”><h2>Related Topics in Forums</h2>’; = To choose a title for this element on your website, the original title is “Related Topics for Forums”.
- <p><?php the_time(‘M j, Y’) ?></p> = This line of code adds the date stamp right below each related topic and you can remove this line if you don’t like to show date stamps.
- <?php the_post_thumbnail(); ?> = This piece of code will fetch and query the post thumbnail or featured image of any selected topic.
Add a featured image for any forum, topic or reply
With the above code, you can display related posts in topics with post thumbnails or featured images. Showing related posts with featured images can grab more attention and increase user engagement. But the main problem is that bbPress does not support post thumbnails for forums, topics or replies. To achieve this, you can simply add the following three lines of code to the end of your functions.php file:
add_post_type_support('forum', array('thumbnail'));
add_post_type_support('topic', array('thumbnail'));
add_post_type_support('reply', array('thumbnail'));
14 English and Persian forums at LELB Society
Below, you can see the list of our 14 English and Persian forums available to our registered students. Our students can easily create a topic in our forums and post their questions or opinions. The team of our educators, including Dr. Mohammad Hossein Hariri Asl, the founder of LELB Society on WordPress and the author of this article, would respond to all created topics immediately and in detail.
- Forum
- Topics
- Last Post
- Best Poems for ESL Students Forum for DiscussionEnjoy best poems for ESL students in this forum based on the English immersion program for discussion and writing practice in an asynchronous mode. Study and write about top-rated poems in English literature. All your comments and replies are evaluated carefully and checked for any grammar mistake.
- 9
- 1 week, 1 day ago
- English Conversation Questions for AdultsEnglish conversation questions for adults to trigger heated discussions and arguments and practice speaking ideal for IELTS candidates and advanced ESL learners. Practice brainstorming in English and become a more fluent speaker of English.
- 46
- 1 week ago
- English Language Forum Ask English QuestionsIn This English language forum, ESL learners can ask us their English questions and expect to receive detailed answers immediately. We'll answer all your questions about English grammar, vocabulary and the like.
- 6
- 1 year, 3 months ago
- FAQ Forum – Ask About LELB Society’s ServicesIf you are an LELB Society's member, you can use this FAQ forum to ask any question you might have about our services. You can also study our Persian guide to learn more about our bilingual academy and wide-ranging services in Farsi. Please take a tour at LELB Society before creating a new topic in this forum.
- 1
- 2 years, 6 months ago
- Feedback Box for LELB Society’s StudentsUse this forum as a feedback box to express your precious opinions, criticism or educational experience freely at LELB Society. You can also give us your testimonials here in this forum. We will certainly treasure and consider all of your opinions and criticism.
- 27
- 3 months, 3 weeks ago
- Film Criticism Course Forum to Practice English & PersianIn this forum, we proudly offer our English and Persian students a film criticism course as one of the most practical ways to immerse themselves in English and Farsi. Our film criticism course includes both synchronous and asynchronous learning systems on the premise of content-based instruction or CBI to make the process of second language acquisition more enjoyable and natural. In this course, we create new topics in this forum for each new film on a weekly basis. Then the students watch the assigned films asynchronously and attend this forum, posting their opinions and criticism based on our round table activity. Finally in our live classes, we mainly concentrate on the posted comments and replies in this forum.
- 63
- 1 week, 2 days ago
- Good Quotes for Discussion Forum for ESL StudentsGood quotes for discussion forum ideal for free discussion and conversation classes organized in interesting and popular topics accessible to LELB Society students and members to prompt challenging discussions and heated arguments.
- 7
- 1 year ago
- IELTS Writing Task 2 Full Analysis ServiceSubmit your essays for IELTS Writing Task 2 to us for in-depth analysis and scoring. Create a new topic and compose your IELTS essay question. Then submit your full essay. We will analyze and evaluate your IELTS essays for free during your monthly membership.
- 1
- 2 years, 6 months ago
- Latest News and Events at LELB SocietyFollow this forum to stay informed about the latest news and events at LELB Society. LELB Society, which is an online bilingual academy of English and Persian, is getting better and better every day. In this forum, we share our crowning achievements with you.
- 7
- 2 years, 3 months ago
- Persian Conversation Questions for SpeakingPractice Persian conversation and speaking in Farsi with these challenging questions in Farsi ideal for Farsi students and learners. We use these challenging Persian questions in our Persian conversation classes. You can also practice speaking in Farsi asynchronously by leaving voice comments and messages.
- 13
- 5 days, 2 hours ago
- Persian Language Forum to Ask Farsi QuestionsPersian Language Forum can be used by non-Persian speakers as Persian learners to exchange their questions and answers in Farsi with their Persian teachers and/or classmates at LELB Society. If you're a Persian / Farsi learner, you might end up having a lot of questions in Farsi, especially Persian grammar. However, in this Persian language forum, we will answer all of your Farsi questions in detail.
- 3
- 2 years, 1 month ago
- Practice Writing in Farsi for Farsi LearnersPractice writing in Farsi / Persian including essay writing in Farsi, summary writing in Farsi, making sentences in Persian, and the like for non-Persian speakers and Farsi students. We will analyze your Persian writings thoroughly.
- 13
- 1 year, 10 months ago
- Storytelling in English to Practice WritingIn this forum, our students can practice storytelling in English in an interactive and creative fashion. This activity can provide our students with this great opportunity to practice writing in a collaborative and asynchronous mode. Storytelling in English in this forum is practiced in the following 2 ways: open-ended storytelling and storyboarding.
- 1
- 2 years, 2 months ago
- Student Portfolio Assessment at LELB SocietyAt LELB Society, we use student portfolio assessment to track the educational progress our students or members make over the passage of time from the first moment they start learning to their current learning status.
- 7
- 1 year, 7 months ago
- Submit Your Post as an Author or Teacher at LELB SocietyCreate a new topic in this forum to submit your post as an author, teacher or contributor at LELB Society. Your posts will be listed on your profile page and in your own name. You need to log in to your account to create a new topic in our forums. Please consider the following before submitting your post to us for publication:
- Study our guest posting guidelines for authors.
- Check out the list of our categories and popular tags to get more familiar with our niche, audience and recommended topics.
- Use the same topic created by you in this forum to request editing or updating your published post.
- Explore the team of authors and contributors at LELB Society.
- 3
- 1 year, 2 months ago
- داستان گویی در فارسی – انجمن آموزش زبان فارسی
داستان گویی در فارسی راهی جذاب و مناسب برای آموزش خواندن و نوشتن فارسی و همچنین رشد خلاقیت کودکان و نوجوانان می باشد. ما برای داستان گویی یا قصه گویی در فارسی در این انجمن آموزش زبان فارسی، از این دو روش استفاده می کنیم: داستان گویی با داستان ناتمام که فارسی آموز آن را کامل می کند، و داستان گویی با استوری بورد که فارسی آموز داستانی را بر اساس تصویری از حوادث داستان که به او داده می شود، به ترتیب زمانی می نویسد.
- 9
- 1 year, 12 months ago
- Best Poems for ESL Students Forum for Discussion
Explore our related posts for each topic
You can check how we’ve been able to display related posts for each single topic in our forums. In the following list, you can browse 15 new topics in our forums. By selecting any one of these topics, you can check related posts at the bottom of each topic.
- Topic
- Voices
- Last Post
Include bbPress forums, topics and replies in search results
Now that your topics and forums are enriched with featured images, why not include them in WordPress search results? As you might already know, bbPress has got its own search box as displayed below applicable only to LELB Society’s forums:
The following php code can include your forums, topics and replies in the default WordPress search box, which is to be found on the main menu at LELB Society as illustrated in the above image. Simply copy and paste this php code in your functions. php file.
function ntwb_bbp_topic_cpt_search( $topic_search ) {
$topic_search['exclude_from_search'] = false;
return $topic_search;
}
add_filter( 'bbp_register_topic_post_type', 'ntwb_bbp_topic_cpt_search' );
function ntwb_bbp_forum_cpt_search( $forum_search ) {
$forum_search['exclude_from_search'] = false;
return $forum_search;
}
add_filter( 'bbp_register_forum_post_type', 'ntwb_bbp_forum_cpt_search' );
function ntwb_bbp_reply_cpt_search( $reply_search ) {
$reply_search['exclude_from_search'] = false;
return $reply_search;
}
add_filter( 'bbp_register_reply_post_type', 'ntwb_bbp_reply_cpt_search' );
Make bbPress even more SEO friendly
Another thing you can do to improve and optimize bbPress for SEO purposes is to add description for each forum on the main forums list as shown above in LELB Society’s forums list. This is also possible by adding the following php code to the end of your functions.php file. Without this code, the description you provide for a forum is not displayed in the forums list.
function rw_singleforum_description() {
echo bbp_forum_content();
}
add_action( 'bbp_template_before_single_forum' , 'rw_singleforum_description');