Can i use 2 page content-forum & content-forum-slug on bbpress?
-
I currently have a bbpress folder in my theme which contains all the theme of my forum. I have a page archive-forum.php which displays the forum page and a page content-single-forum.php which displays the topics. I would like to know how to create a different display for a forum. I would like to display the first forum with a content-single-forum-slug.php and the other forums with content-single-forum.php. I have tried all : content-single-forum-slug.php, single-forum-slug.php, content-single-slug.php, single-slug.php. I didn’t succeed so I think it’s not possible.
-
Up
no one has any ideas?
With the query monitor plugin, I see that I have to use a php page like this : single-forum-rules.php. Rules being my slug. I create a page single-forum-rules.php but it does not work. It always takes the page.php file. But if I remove the “-rules” it works I have a white page with written “page rules load”…
Any idea how to force it to find the right page?
I am very unclear as to what you are trying to achieve.
if you want one forum say forum id 12345 to display differently, then just amend content-single-forum to
<?php $forum_id = bbp_forum_id() ; if $forum_id = '12345' { ?> <div id="bbpress-forums" class="bbpress-wrapper"> <?php bbp_breadcrumb(); ?> <?php bbp_forum_subscription_link(); ?> <?php do_action( 'bbp_template_before_single_forum' ); ?> <?php if ( post_password_required() ) : ?> <?php bbp_get_template_part( 'form', 'protected' ); ?> <?php else : ?> <?php bbp_single_forum_description(); ?> <?php if ( bbp_has_forums() ) : ?> <?php bbp_get_template_part( 'loop', 'forums' ); ?> <?php endif; ?> <?php if ( ! bbp_is_forum_category() && bbp_has_topics() ) : ?> <?php bbp_get_template_part( 'pagination', 'topics' ); ?> <?php bbp_get_template_part( 'loop', 'topics' ); ?> <?php bbp_get_template_part( 'pagination', 'topics' ); ?> <?php bbp_get_template_part( 'form', 'topic' ); ?> <?php elseif ( ! bbp_is_forum_category() ) : ?> <?php bbp_get_template_part( 'feedback', 'no-topics' ); ?> <?php bbp_get_template_part( 'form', 'topic' ); ?> <?php endif; ?> <?php endif; ?> <?php do_action( 'bbp_template_after_single_forum' ); ?> </div> <?php } else { ?> <div id="bbpress-forums" class="bbpress-wrapper"> <?php bbp_breadcrumb(); ?> <?php bbp_forum_subscription_link(); ?> <?php do_action( 'bbp_template_before_single_forum' ); ?> <?php if ( post_password_required() ) : ?> <?php bbp_get_template_part( 'form', 'protected' ); ?> <?php else : ?> <?php bbp_single_forum_description(); ?> <?php if ( bbp_has_forums() ) : ?> <?php bbp_get_template_part( 'loop', 'forums' ); ?> <?php endif; ?> <?php if ( ! bbp_is_forum_category() && bbp_has_topics() ) : ?> <?php bbp_get_template_part( 'pagination', 'topics' ); ?> <?php bbp_get_template_part( 'loop', 'topics' ); ?> <?php bbp_get_template_part( 'pagination', 'topics' ); ?> <?php bbp_get_template_part( 'form', 'topic' ); ?> <?php elseif ( ! bbp_is_forum_category() ) : ?> <?php bbp_get_template_part( 'feedback', 'no-topics' ); ?> <?php bbp_get_template_part( 'form', 'topic' ); ?> <?php endif; ?> <?php endif; ?> <?php do_action( 'bbp_template_after_single_forum' ); ?> </div> <?php } ?>
and change whichever display you want
Hi @outkax 👋
The functionality you’re looking for does not currently exist.
The
bbp_get_template_part
filter exists to hook into this API and extend the template parts to attempt to locate, so it would be achievable with some custom code.I tested with your code Robin, it does not work. The if is missing parentheses. But even with that doesn’t work. It displays all the forums with the content of the if and does not take into account the id I give it.
I tried another method but no way bbp_forum_id only displays the forum id.I tried with I tried with “bbp_get_forum_id” that doesn’t work either.
<div id="bbpress-forums" class="bbpress-wrapper"> <?php bbp_breadcrumb(); ?> <?php //bbp_forum_subscription_link(); ?> <?php do_action( 'bbp_template_before_single_forum' ); ?> <?php if ( post_password_required() ) : ?> <?php bbp_get_template_part( 'form', 'protected' ); ?> <?php else : ?> <?php //bbp_single_forum_description(); ?> <?php if ( bbp_has_forums() ) : ?> <?php bbp_get_template_part( 'loop', 'forums' ); ?> <?php endif; ?> <?php if ( ! bbp_is_forum_category() && bbp_has_topics() ) : ?> <?php bbp_get_template_part( 'pagination', 'topics' ); ?> <?php bbp_get_template_part( 'loop', 'topics' ); ?> <?php bbp_get_template_part( 'pagination', 'topics' ); ?> <?php bbp_get_template_part( 'form', 'topic' ); ?> <?php elseif ( ! bbp_is_forum_category() ) : ?> <?php if(bbp_forum_id() === '513'): ?> <?php echo 'yes'; ?> <?php else : ?> <?php bbp_get_template_part( 'feedback', 'no-topics' ); ?> <?php bbp_get_template_part( 'form', 'topic' ); ?> <?php ?> <?php endif; ?> <?php endif; ?> <?php endif; ?> <?php do_action( 'bbp_template_after_single_forum' ); ?> </div>
sorry, untested code, go with
if ($forum_id == ‘12345’) {
I think I found the solution 🙂 :
<?php /** * Single Forum Content Part * * @package bbPress * @subpackage Theme */ // Exit if accessed directly defined( 'ABSPATH' ) || exit; ?> <div id="bbpress-forums" class="bbpress-wrapper"> <?php bbp_breadcrumb(); ?> <?php //bbp_forum_subscription_link(); ?> <?php do_action( 'bbp_template_before_single_forum' ); ?> <?php if ( post_password_required() ) : ?> <?php bbp_get_template_part( 'form', 'protected' ); ?> <?php else : ?> <?php //bbp_single_forum_description(); ?> <?php if ( bbp_has_forums() ) : ?> <?php bbp_get_template_part( 'loop', 'forums' ); ?> <?php endif; ?> <?php if ( ! bbp_is_forum_category() && bbp_has_topics() ) : ?> <?php bbp_get_template_part( 'pagination', 'topics' ); ?> <?php bbp_get_template_part( 'loop', 'topics' ); ?> <?php bbp_get_template_part( 'pagination', 'topics' ); ?> <?php bbp_get_template_part( 'form', 'topic' ); ?> <?php elseif ( ! bbp_is_forum_category() ) : ?> <?php if(bbp_get_forum_id() === $forum_id = 513): ?> <?php bbp_get_template_part( 'rules' ); ?> <?php else : ?> <?php bbp_get_template_part( 'feedback', 'no-topics' ); ?> <?php bbp_get_template_part( 'form', 'topic' ); ?> <?php ?> <?php endif; ?> <?php endif; ?> <?php endif; ?> <?php do_action( 'bbp_template_after_single_forum' ); ?> </div>
your triple
===
means that is has to match type (eg string or integer) as well as value, hence whyif(bbp_forum_id() === '513')
didn’t work, as the forum id is an integer and by havng quotes round the number you are asking it to be a string
in your solution
<?php if(bbp_get_forum_id() === $forum_id = 513): ?>
would be better as
<?php if(bbp_get_forum_id() === 513): ?>
or better still
<?php if(bbp_get_forum_id() == 513): ?>
as unless you are using the $forum_id variable elsewhere (when it probbaly needs to be declared as a global) then the
$forum_id =
is redundantbut glad you fixed it
Thanks for your answer I have corrected my code with yours 🙂
🙂
Hi. Nice one! this is also my exact concern, I’m very thankful to see this in the forum. It is also a big help for me, I successfully fixed and corrected my codes. Thanks again.
🙂
- You must be logged in to reply to this topic.