Dynamic Post Sliders in Bricks with BricksExtras and WP Grid Builder

This article provides the answer to

We are going to set up a Bricks query loop that shows the posts of a Custom Post Type with BricksExtrasPro Slider in the loop. When the CPT items are filtered by their taxonomy using WP Grid Builder, the sliders will not appear (they will still take up space).

I initially tried to solve this using the change event, but the correct one to use is appended.

Quoting WP Grid Builder developer, Loïc Blascos:

About the slider, you should not use “change” event but “appended” event: https://docs.wpgridbuilder.com/resources/event-facet-appended/
The DOM will only be available on appended.

When you filter, the old content is removed from the page and the new content is appended.
So you can’t refresh something. You have to initialize the script again for it to work.
And this can only be done when the new content is present in the page (appended event).

Here’s how the CPT archive template is structured:

The Facet element is via WPGB’s Bricks’ add-on.

The two Slide elements in the Pro Slider were deleted, Gallery mode was enabled and a Pro Slider Gallery element was added inside set to

{acf_testimonial_gallery}

where testimonial_gallery is a Gallery type of custom field attached to testimonials using ACF Pro.

Add the JavaScript that calls the BricksExtras’ function that creates the slider.

Settings (gear icon) → PAGE SETTINGS → CUSTOM CODE → Body (footer) scripts:

<script>
window.WP_Grid_Builder &&
WP_Grid_Builder.on("init", function (wpgb) {
    wpgb.facets &&
    wpgb.facets.on("appended", function (args) {
        doExtrasSlider(document.getElementById("brxe-roadst"))
    })
})
</script>

where brxe-roadst is the ID of the query loop’s parent Container.

If you prefer adding the JS via the child theme instead of adding it in the Bricks template, in child themes functions.php inside the anonymous function hooked to wp_enqueue_scripts, add:

if ( is_post_type_archive( 'testimonial' ) ) {
			wp_enqueue_script( 'testimonial', get_stylesheet_directory_uri() . '/assets/js/testimonial.js', [], filemtime( get_stylesheet_directory() . '/assets/js/testimonial.js' ), true );
		}

and the code in assets/js/testimonial.js:

document.addEventListener("DOMContentLoaded", () => {
  window.WP_Grid_Builder &&
	WP_Grid_Builder.on("init", function (wpgb) {
	  wpgb.facets &&
		wpgb.facets.on("appended", function (args) {
		  doExtrasSlider(document.getElementById("brxe-roadst"))
		})
	})
})
Get access to all 524 Bricks code tutorials with BricksLabs Pro

Leave the first comment

 

Related Tutorials..

Pro
WP Grid Builder Filters inside Bricks’ OffCanvas

WP Grid Builder Filters inside Bricks’ OffCanvas

This Pro tutorial provides the steps to move WP Grid Builder's filters inside the Bricks' native Offcanvas on smaller viewport widths. Let's work with the…
How to add a custom SwiperJS slider in Bricks

How to add a custom SwiperJS slider in Bricks

In this tutorial, we'll show you how to integrate a custom slider in Bricks using the SwiperJS library and how to add custom parameters using…
Categories:
Tags:
Pro
Custom Meta Box Thumbnail Slider in WordPress

Custom Meta Box Thumbnail Slider in WordPress

This Pro tutorial provides the steps to set up an image and YouTube video thumbnail slider in WordPress using Splide and Meta Box. The site…
Categories:
Tags:
Pro
Bricks Slider Images From ACF Flexible Content Sub Field

Bricks Slider Images From ACF Flexible Content Sub Field

Consider the following field group associated with Pages when using ACF Pro: "Page Fields" field group|_"Page Content" Flexible Content field|__"Layout 1" layout|___"Title" Text field|___"Layout 1…
How to create a dynamic infinite logo slider with ACF and Bricks

How to create a dynamic infinite logo slider with ACF and Bricks

This tutorial provides the builder settings, PHP & CSS codes that can be pasted in order to create an infinite logo slider in pure CSS…
Pro
How to Limit a WP Grid Builder’s Term Grid to Only Current Post Terms

How to Limit a WP Grid Builder’s Term Grid to Only Current Post Terms

In the WP Grid Builder Facebook group (unofficial), a user asks: Hi All, I'm looking for a way to update the contents of a grid…
Categories:
How to Create a Grid Slider in Bricks

How to Create a Grid Slider in Bricks

In this tutorial, we'll learn how to create multiple rows and columns inside the default nested slider of Bricks. Introduction A user recently asked in…
Categories: