Dynamic Multiple Galleries in Bricks Using Meta Box

This Pro tutorial provides the steps to set up multiple galleries per page in Bricks using Meta Box cloneable Group field having an Image Advanced sub field.

When editing a Page:

After implementing the tutorial, on the front end:

Update: Added instructions for showing custom gallery titles.

Screenshots: 1, 2.

Step 1

Install and activate Meta Box and Meta Box AIO plugins.

Import this field group or set it up for Pages like this:

Step 2

Edit your Pages. Add as many galleries as needed for each and upload/select images.

Step 2

Edit the template that applies to all the Pages with Bricks.

Copy this JSON and paste to import the Section.

We have applied a Dynamic data condition to the Section to ensure that it gets output only if there is at least 1 page gallery for the current Page.

The first Heading's text is set to "Page". We are going to append " Galleries" or " Gallery" to it conditionally based on the number of galleries.

"Use query loop" is ticked for the Block and the Query Type set to MB Group: Page Galleries.

Image Gallery element's source has been set to:

{echo:bl_get_page_gallery}

where bl_get_page_gallery() is a custom function that we are going to define in the next step.

The text of Heading above the Image Gallery is set to:

Gallery {echo:bl_get_loop_index}

bl_get_loop_index() is a custom function that we are going to define in the next step.

This will print "Gallery 1", "Gallery 2" headers - as many as the number of page galleries.

Step 3

Add the following in child theme's functions.php or a code snippets plugin:

This is a BricksLabs Pro tutorial.

For full access login below or create your BricksLabs Pro account

Get access to all 526 Bricks code tutorials with BricksLabs Pro

Related Tutorials..

Pro
Meta Box Group Subfield Text’s Slug as Query Loop Item ID in Bricks

Meta Box Group Subfield Text’s Slug as Query Loop Item ID in Bricks

In the BricksLabs Facebook group a user asks: I have a metaBox custom field called 'section_title' inside a clonable metabox group called 'about_section' How can…
Categories:
Tags:
Pro
Meta Box Checkbox List Query Type in Bricks

Meta Box Checkbox List Query Type in Bricks

This Pro tutorial provides the steps to add a new query type in Bricks builder for displaying the values of a Checkbox List type of…
Categories:
Pro
Meta Box Color Picker to CSS Custom Property Workflow in Bricks

Meta Box Color Picker to CSS Custom Property Workflow in Bricks

This Pro tutorial provides the steps to declare a custom property (CSS variable) whose value is equal to the post-specific color set via a custom…
Categories:
Tags: