Archived topic
bbpress forum question
11 replies · Started by Are Martin on September 13, 2015
Hi Tom, I recently started using bbpress on my site. But I´d like the forum archive page to have a different layout then the other archive pages. I currently have the blog page and category archives set to sidebar/content/sidebar. However, I would like the forum archive page which lists my forums to have a different layout then the rest of the archive pages. I would like this page to have a sidebar/content layout.
How would I target the forum archive page with css to achieve this?
Regards
Are Martin Kallåk
to clarify.... I actually need the same layout for all the bbpress forum pages. I use two sidebars on all the other pages on my site but I need one of the sidebars to disappear on all the bbpress forum pages. Since bbpress uses custom post types I can not do this with the standard GP meta box for sidebar layout.
I therefore tried to target the forums using css and
#bbpress-forums .left-sidebar {
display: none;
}
which is probably missing something important. I´m a novice at this so this completely random trial and error.
Any idea how to do this using css?
Hi Are Martin. Based on the information Tom provided in this post it appears that the bbPress forum page layout is set in Customizer > Layout > Blog Sidebar Layout.
Thanks for your answer! :) I know I can change the layout in the customizer. But the problem is that this also changes the blog page and I need bbpress forum pages to have a different layout then the blog page.
Got it. Another option might be to use a function to set the layout using a test for "is_buddypress()". Here is a KB article that discusses setting sidebar layouts.
We have a cool filter for this :)
add_filter( 'generate_sidebar_layout','generate_custom_buddypress_sidebar_layout' );
function generate_custom_buddypress_sidebar_layout( $layout )
{
// If we are on a buddypress page, set the sidebar
if ( is_buddypress() )
return 'both-left';
// Or else, set the regular layout
return $layout;
}
Adding PHP: https://generatepress.com/knowledgebase/adding-php-functions/
Cool! So if understand this correctly I can use this same filter using various conditional template tags to target specific pages within buddy press or bbpress?
So for example if I wanted to target only the activity page in buddypress I could use the bp_is_activity_front_page() tag so the code would be:
add_filter( 'generate_sidebar_layout','generate_custom_buddypress_sidebar_layout' );
function generate_custom_buddypress_sidebar_layout( $layout )
{
// If we are on a buddypress page, set the sidebar
if ( bp_is_activity_front_page() )
return 'both-left';
// Or else, set the regular layout
return $layout;
}
I just change the conditional tag to the template tag that correspond with the specific page I like to change the layout for? Correct?
Correct :)
Hi Tom, this worked! :) But how can I use multiple conditional template tags in the same filter? I have several template tags i´d like the same output for.
You would use the PHP logical "OR" operator:
if ( bp_is_activity_front_page() || bp_is_home() || bp_is_blog_page() )
return 'some-value';
Ref: http://php.net/manual/en/language.operators.logical.php
Thanks! :) That worked perfectly!
You're welcome. Glad it worked :)
