Skip to:
Content
Pages
Categories
Search
Top
Bottom

Template in Block Themes?


  • chenryahts
    Participant

    @chenryahts

    BBpress keeps loading the empty index.php in the TwentyTwentyTwo Child theme I’m working on, which loads a WSOD.

    I can’t get any of the template filters to use one of the html files, so temporarily have it working with the index.php file as:

    wp_head();
    block_header_area();
    block_template_part( 'page-inner' );
    wp_footer();
    block_footer_area();

    And… its almost all working? But, this can’t be the right way to get it to use the new default page template in the block theme.

    Thoughts? Ideas? How can I get it to use the new theme templates?

    Thanks!

Viewing 16 replies - 1 through 16 (of 16 total)

  • Robin W
    Moderator

    @robin-w

    add this plugin

    bbp style pack

    then go to

    dashboard>settings>bbp style pack and the tab will let you fix this issue


    chenryahts
    Participant

    @chenryahts

    @robin-w

    Thank you, I’ll try it!


    chenryahts
    Participant

    @chenryahts

    @robin-w

    I tried the settings under ‘Forum Templates’ but I’m getting the same WSOD. bbpress just isn’t loading anything other than the blank index.php in the block theme.

    Is there another setting I’m missing? Is anyone using bbpress with a block theme yet?

    Thank you again for your suggestion!


    Robin W
    Moderator

    @robin-w

    no it’s my bad coding !!

    I hadn’t spotted that you were using a child theme.

    I add some code to pick up on this, and be back in the next day


    Robin W
    Moderator

    @robin-w

    ok, I’ve released version 5.0.6 of my style pack plugin.

    Once you have updated to this version you will find

    dashboard>settings>bbp style pack>theme support where you can enable theme support for your 2022 child theme

    please confirm that this works


    chenryahts
    Participant

    @chenryahts

    @robin-w

    I’m still getting the WSOD when I try to go to the forums archive or to any top level forums. We’re also using Buddypress, and the Group Forums are working using the templates that Buddypress is loading.

    So I’m not sure what’s gone wrong.

    I don’t see the child theme listed, only Twentytwentytwo, does that matter?

    Thank you,


    Robin W
    Moderator

    @robin-w

    I took it from

    BBpress keeps loading the empty index.php in the TwentyTwentyTwo Child theme

    that you were using a child theme.

    what thene are you using?


    chenryahts
    Participant

    @chenryahts

    Yep, using a child theme. But, the child theme isn’t listed, only twentytwentytwo itself, and selecting it didn’t change anything.

    So, maybe I misunderstood your directions, but this did not solve the issue. I still get a blank white page.

    I’m happy to test something else or troubleshoot it.


    Robin W
    Moderator

    @robin-w

    if you have upgraded, then you should see this as text in the theme support tab

    You are using the theme Twenty Twenty-Two or a Twenty Twenty-Two child theme – enable this section to get bbpress to display correctly


    chenryahts
    Participant

    @chenryahts

    Hi @robin-w,

    I finally got to check it, and no, using the bbp-style-pack with the checkbox enabled still didn’t work.

    I’ve got it working copying the template-canvas.php file over to /theme/bbpress/page.html

    I’m sure this isn’t the right way to do it, but on it’s own, it’s won’t load with the block page.

    Thank you so much for your help,


    Robin W
    Moderator

    @robin-w

    🙂


    codejp3
    Participant

    @codejp3

    Using the clues in this topic, this is what I have working for ANY FSE Block theme with the wonderful style-pack plugin:

    
    function fse_bbpress_template( $template ) {
    	$template = ABSPATH . WPINC . '/template-canvas.php';
    	return $template;
    }
    
    function fse_bbp_theme_compat( $template ) {
    	$template= BSP_PLUGIN_DIR.'/templates/bbpress.php';
    	return $template;
    }
    
    if ( ! function_exists( 'fse_bbpress_support' ) ) {
    	function fse_bbpress_support() {
    		// gt current theme dir
    		$theme_dir = get_template_directory();
    
    		// Detect if FSE theme or traditional.
    		// FSE Block themes require a theme.json file.
    		// Use that to check instead of theme name or parent theme name.
    		// Perhaps a better method is available, but this works for now.
    		$fse_theme = false;
    		if ( file_exists( $theme_dir.'/theme.json' ) ) { $fse_theme = true; }
    		
    		if ( !$fse_theme ) { return; }
    		
    		// disabled because it doesn't seem to be needed, regardless of style pack 
    		// $bsp_style_settings_theme_support['twentytwentytwo_activate'] setting
    		// template-canvas.php seems to be included by default
    		
    		//add_filter( 'template_include', 'fse_bbpress_template' );
    		
    		add_filter ( 'bbp_template_include_theme_compat' , 'fse_bbp_theme_compat' );
    	
    	}
    	
    }
    add_action( 'after_setup_theme', 'fse_bbpress_support' );
    

    and this little helper function helped me figure out what template was getting loaded in the first place:

    
    function fse_bbpress_print_template() {
    	if ( is_bbpress() ) {
    		//echo at the bottom of the page visibly
    		echo get_page_template();
    		
    		// or echo the template silently as an HTML comment
    		// echo '<!-- ' . get_page_template() . ' -->';
    	}
    }
    // DISABLE THIS ACTION HOOK AS SOON AS POSSIBLE! DO NOT LEAVE IT ACTIVE WHEN DEBUGGING IS DONE!
    add_action( 'bbp_template_after_forums_loop', 'fse_bbpress_print_template' );
    

    I’ve tried this on a few different FSE Block themes, and BBPress is displaying properly, and the style tweaks from the wonderful Style-Pack plugin are being applied.

    Like I said, it’s working regardless of the $bsp_style_settings_theme_support[‘twentytwentytwo_activate’] setting within the BSP plugin, but it uses the template from the plugin so it would still need to be installed an active, even without any styling tweaks applied.

    It’s not a permanent solution, but perhaps aspects of this could be applied to the BSP plugin, or your own custom solution.


    Robin W
    Moderator

    @robin-w

    thanks – I’ll take a look 🙂


    codejp3
    Participant

    @codejp3

    @robin-w or another mod – can you please delete:
    https://bbpress.org/forums/topic/template-in-block-themes/#post-232249 (#post-232249)
    https://bbpress.org/forums/topic/template-in-block-themes/#post-232250 (#post-232250)
    https://bbpress.org/forums/topic/template-in-block-themes/#post-232256 (#post-232256)
    They had issues and take up a lot of wasted space.

    Seriously done this time! No more changes/revisions! It is what it is!

    Posting a much cleaner revision of the code above.

    • This one will work with either the BBPress Style Pack plugin template (looks great!) or the default BBPress template (looks horrible!).
    • It will optionally include the required ‘template-canvas.php’ only if it’s missing.
    • It will also only affect BBPress pages, not the rest of the site.
    • It will also only affect FSE Block themes.
    • If using default BBPress templates, it includes checks for if on forum root index page and loads extras/archive-forum.php (to prevent double-listing of the forum index), and loads extras/page-front-forums.php for “the rest of bbpress” (to prevent “nothing found” errors)
    
    // function to include the wp-includes/template-canvas.php file if needed
    function fse_bbpress_template( $template ) {
    	
    	if ( is_bbpress() ) {
    	
    		$template = ABSPATH . WPINC . '/template-canvas.php';
    		
    	}
    	
    	return $template;
    	
    }
    
    // function to include the bbpress forum template file if needed
    function fse_bbp_theme_compat( $template ) {
    
    	if ( is_bbpress() ) {
    
    		// BBPress Style Pack Plugin Forums Index Template
    		if ( defined( 'BSP_PLUGIN_DIR' ) ) {
    
    			$template = BSP_PLUGIN_DIR . '/templates/bbpress.php';
    
    		} else {
    
    			// Default BBPress
    			// if current page is bbpress forum root page, load archive-forum to prevent double-listing of index
    			if ( isset( get_queried_object()->name ) ) {
    				if ( get_queried_object()->name == 'forum' ) {
    
    					$template = WP_CONTENT_DIR . '/plugins/bbpress/templates/default/extras/archive-forum.php';
    
    				}
    
    			// else, load page-front-forums or the rest of bbpress is broken with empty pages
    			} else {
    
    				$template = WP_CONTENT_DIR . '/plugins/bbpress/templates/default/extras/page-front-forums.php';
    
    			}
    			
    		}
    		
    	}
    	
    	return $template;
    
    }
    
    // main function for handling which theme file needs to be included
    if ( ! function_exists( 'fse_bbpress_support' ) ) {
    	function fse_bbpress_support() {
    		
    		// get current theme dir
    		$theme_dir = get_template_directory();
    
    		/* 
    		* Detect if FSE theme or traditional.
    		* FSE Block themes require a theme.json file.
    		* Use that to check instead of theme name or parent theme name.
    		* Perhaps a better method is available, but this works for now
    		*/ 		
    		if ( file_exists( $theme_dir . '/theme.json' ) ) {
    
    			// include wp-includes/template-canvas.php only if needed
    			if ( !basename( get_page_template() ) == 'template-canvas.php' ) {
    
    				add_filter( 'template_include', 'fse_bbpress_template' );
    
    			}
    
    			// include either the BSP template, or default BBPress template
    			add_filter ( 'bbp_template_include_theme_compat', 'fse_bbp_theme_compat' );
    
    		}
    	
    	}
    }
    add_action( 'after_setup_theme', 'fse_bbpress_support' );
    

    One issue with EVERY default BBPress template is that the header/footer/sidebar are trying to be pulled from template files that don’t exist in block themes. They’re being included, but don’t look right. I’m not sure of the best solution for that, other than to use the BBPress Style Pack Plugin which takes care of that and looks great.


    Robin W
    Moderator

    @robin-w

    @codejp3 thanks for all your efforts on this, much appreciated.

    I have now incorportated your code into my plugin.

    Great work 🙂


    dina920
    Participant

    @dina920

    This working thank you guys.

Viewing 16 replies - 1 through 16 (of 16 total)
  • You must be logged in to reply to this topic.
Skip to toolbar