[Resolved] bbpress forum question

Home Forums Support [Resolved] bbpress forum question

Home Forums Support bbpress forum question

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #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

    #136583
    Are 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?

    #136584
    bdbrown

    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.

    #136585
    Are 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.

    #136586
    bdbrown

    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.

    #136631
    Tom
    Lead Developer
    Lead Developer

    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/

    #136662
    Are 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?

    #136738
    Tom
    Lead Developer
    Lead Developer

    Correct 🙂

    #137057
    Are 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.

    #137064
    bdbrown

    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

    #137068
    Are Martin

    Thanks! 🙂 That worked perfectly!

    #137069
    bdbrown

    You’re welcome. Glad it worked 🙂

Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.