- This topic has 11 replies, 3 voices, and was last updated 7 years, 8 months ago by
bdbrown.
-
AuthorPosts
-
September 13, 2015 at 3:18 pm #136571
Are Martin
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
September 13, 2015 at 5:15 pm #136583Are Martin
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?
September 13, 2015 at 5:30 pm #136584bdbrown
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.
September 13, 2015 at 5:38 pm #136585Are Martin
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.
September 13, 2015 at 5:55 pm #136586bdbrown
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.
September 13, 2015 at 11:41 pm #136631Tom
Lead DeveloperLead DeveloperWe 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/
September 14, 2015 at 2:22 am #136662Are Martin
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?
September 14, 2015 at 9:56 am #136738Tom
Lead DeveloperLead DeveloperCorrect 🙂
September 15, 2015 at 2:16 pm #137057Are Martin
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.
September 15, 2015 at 3:11 pm #137064bdbrown
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
September 15, 2015 at 4:38 pm #137068Are Martin
Thanks! 🙂 That worked perfectly!
September 15, 2015 at 4:47 pm #137069bdbrown
You’re welcome. Glad it worked 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.