27th Apr '23
/
0 comments

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 633 Bricks code tutorials with BricksLabs Pro

Related Tutorials..

Pro
Conditionally outputting an element in a Query Loop based on date-type custom field

Conditionally outputting an element in a Query Loop based on date-type custom field

This Pro tutorial shows how to output an element in a Bricks' query loop only if the value of a date-type of custom field for…
Categories:
Meta Box Category Colors in Single Posts

Meta Box Category Colors in Single Posts

Looking to use Meta Box Color Picker fields' values in a single post Bricks template based on the post category? This tutorial shows how. Note:…
Categories:
Tags:
Pro
Button to Open Bricks Gallery

Button to Open Bricks Gallery

How to trigger a click on the first image of a gallery in Bricks when a button is clicked.
Categories:
Pro
Sort Posts by Meta Box Group Sub Field in Bricks

Sort Posts by Meta Box Group Sub Field in Bricks

This Pro tutorial provides the steps to order posts in Bricks by the value of a Number-type of sub field that is inside a Meta…
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
Random images from ACF Options Gallery in Bricks

Random images from ACF Options Gallery in Bricks

This Pro tutorial provides the steps to output images from an ACF Gallery-type custom field in a Bricks query loop randomly with each image appearing…
Categories: