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 610 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
Ordering Meta Box group rows by a sub field in Bricks

Ordering Meta Box group rows by a sub field in Bricks

In the BricksLabs Facebook group a user asks: Any idea how to set the sort order of a cloneable group in the query? In this…
Pro
Update Post Meta From Another Custom Field’s Value on Post Publish/Update when using Meta Box

Update Post Meta From Another Custom Field’s Value on Post Publish/Update when using Meta Box

In the Meta Box Facebook group a user asks: Hi all, wondering if I can get some help. For custom field 1, I am using…
Categories:
Tags:
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:
Pro
Meta Box Group’s Number Sub Field Values Sum

Meta Box Group’s Number Sub Field Values Sum

In the Bricks Facebook group a user asked: We can define a custom function that takes a Meta Box group ID, the sub field ID…
Categories:
Tags:
Pro
Adding FAQ page Schema with SlimSeo Schema & Meta Box

Adding FAQ page Schema with SlimSeo Schema & Meta Box

SlimSeo Schema is a plugin by the people behind both SlimSEO & Meta Box. It takes care of adding all the page schema across your…
Categories:
How to create filters with IsotopeJS in Bricks (Part 2): Dynamic Image Galleries

How to create filters with IsotopeJS in Bricks (Part 2): Dynamic Image Galleries

This tutorial series will review how to create a dynamic filterable image gallery using the IsotopeJS library‘s features in Bricks. Requirements Create a custom taxonomy for your…