Beaver Builder Template Rendering

Hey guys, I realize this might be outside of scope for support, but I thought I’d post this anyway.

Per this post: http://forum.wpbeaverbuilder.com/support/q/best-way-to-programmatically-render-a-beaver-template-example-archives-pages/ I’ve been able to create a hard-coded template (example single.php) and insert code that renders a BB template inside that template.

Here is the code I’m using:

<?php

/*
	Template Name: Example
*/

get_header(); ?>

<?php

// WP_Query arguments
$args = array (
    'name'                   => 'masthead',
    'post_type'              => 'fl-builder-template',
);

// The Query
$query = new WP_Query( $args );

// The Loop
if ( $query->have_posts() ) {
    while ( $query->have_posts() ) {
        $query->the_post();
echo the_content();
    }
} else {
    // no posts found
}

// Restore original Post Data
wp_reset_postdata();
?>

<div class="container">
    <div class="row">

        <?php FLTheme::sidebar('left'); ?>
        
        <div class="fl-content <?php FLTheme::content_class(); ?>">
            <?php if(have_posts()) : while(have_posts()) : the_post(); ?>
                <?php get_template_part('content', 'single'); ?>
        	<?php endwhile; endif; ?>
        </div>
        
        <?php FLTheme::sidebar('right'); ?>
        
    </div>
</div>

<?php get_footer(); ?>

I then have the following code within functions.php (a chunk borrowed from another post in the support forums):

// Add BB css and javascript from specific post ID globally
function my_global_builder_posts($post_ids) {
    $posts = get_posts(array( 'post_type' => 'fl-builder-template', 'posts_per_page' => -1 ) );
    foreach($posts as $post) {
       $post_ids[] = $post->ID;
    }
    return $post_ids;
}
add_filter('fl_builder_global_posts', 'my_global_builder_posts');

// Alter BB plugin custom post-type registration
add_action( 'init', 'bb_post_type_override' );
function bb_post_type_override() {
  register_post_type( 'fl-builder-template',
    array(
      'public' => true, 
      'exclude_from_search' => false,
      'label' => 'Page Builder Templates',
    )
  );
}

All works well, but I’ve discovered a possible CSS override that might be part of a bigger picture issue I’m not seeing. Basically, I’m unable to edit the minimum height of the Content Slider module and have that height work. So if I set the height at 800px, it stays at 400px.

If I remove the fl_builder_global_posts filter, all is well again, however my BB templates don’t render anymore.

Any ideas? Perhaps this is besides the point with a BB plugin update that should be coming out soon?

Thanks as always guys!

  • Desmond

Hey Desmond,

If you send me a link to the page in question I can see where the override might be coming from. We don’t have anything for that in the update, but I could whip up some CSS for you. Let me know.

Justin

[Content Hidden]

Hey Desmond,

It looks like we have some unnecessary CSS that is causing trouble. I’ll get a fix out in the next update. For now, you can remove this CSS from modules/content-slider/css/frontend.css…

.fl-content-slider,
.fl-content-slider .fl-slide {
    	min-height: 100%;
}

You’ll need to clear the builder cache after doing that. The min-height value is being explicitly set using the height entered in the settings, so that CSS is not necessary. Let me know if that doesn’t work.

Justin

Also, beautiful work as always! :slight_smile:

That did the trick – thanks Justin, you are the man!

Desmond - this is almost exactly what I think I’m looking for, but I have a few questions if you don’t mind.

I’m using Genesis with Dynamik (default skin) for 90% of a site. I want to create php files for single blog posts, categories and archives that use a BB template.

I tried your code, but get a ‘fatal error Class ‘FLTheme’ not found in…’ and I’m wondering if this requires the BB theme to work properly.

Any thoughts on this issue and my question in general are greatly appreciated.

Hi Keith,

The FLTheme class is included in the Beaver Builder theme, so you will need that for Desmond’s code to work properly. Feel free to post what you’re trying to do and I’ll see if I can help.

Justin

I’d like to create single, author, category and archive pages that, ideally, allow me to use the BB ‘Blog’ element to display posts.

I’ve looked at customizing the actual php files, but I can’t seem to find a way to do that which allows me to use the BB Blog element.

Does that explain what I’m trying to do well enough? It would be REALLY cool if BB allowed for replacement and styling of those templates - for example:

  1. Create a template in BB where you could do something like put in a row, then a Header and, instead of actually writing the header text, tell it to pull in the Title of the post.
  2. Same goes for inserting the Featured image - the template would allow for placement of the Featured Image and allow you to pull in the featured image into that area.
  3. And so on with the content of the post or any specific elements used in the post, such as custom fields.

Kind of like how this plugin allows you to style specific templates, but the BB way:

https://wordpress.org/plugins/wp-custom-post-template/screenshots/

Hey Keith,

Thanks for the detailed post! That’s a great idea, and it’s part of our long term plans, but it’s not possible in the current version. Sorry I don’t have a better answer at this time.

Justin