8th Aug '22
/
10 comments

Dynamic Posts Lightbox in Bricks using GLightbox

Updated on 7 Nov 2022

This Pro tutorial provides the steps to set up a dynamic lightbox using Bricks' query loop with featured images and post titles opening a lightbox having the title, image and excerpt using GLightbox.

When the lightbox is open the previous and next post's lightbox content can be accessed using either the left and right arrows or by pressing ← and → keys. Also, the lightbox can be closed by clicking the x icon or pressing the Esc key.

Needless to say, we have complete control w.r.t the trigger i.e., what should be clicked to open the lightbox and what is shown in the lightbox i.e., the lightbox content.

Note

The post-specific info shown in the lightbox is not fetched using AJAX on-demand, but rather present as a hidden div for each post.

Step 1

Edit your Template/Page with Bricks.

Add a Section and inside the Section's Container, a Block.

This Block is going to be the parent element of posts.

Add this in the Custom CSS area to arrange the posts using CSS Grid:

root { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); grid-column-gap: 40px; grid-row-gap: 60px; }

Add a Div/Block inside the above Block.

Enable query loop on this Div.

Click the query icon and select your desired post type. This step is not needed if you are working with a page where the main query already contains a bunch of posts like the Posts page (blog posts index) or an archive template.

Add your desired trigger content inside the above Div. Ex.: Post Title element and Image element. Do NOT set these individual elements to be hyperlinks.

Add a Block (labelled "Lightbox Content" in the screenshot below) and add your desired lightbox content inside.

Note: Styling for the elements that make up the lightbox content attached to the IDs is not going to remain/work inside the lightbox. Therefore, ensure that any styling is done using classes for them.

In this example I've given the bottom Image element a class of lightbox-posts__lightbox-image and set a top and bottom margin for it.

Once you are done setting up your Lightbox Content, set its Display to none.

This is a BricksLabs Pro tutorial.

For full access login below or create your BricksLabs Pro account

Get access to all 630 Bricks code tutorials with BricksLabs Pro

Related Tutorials..

How to add a layout toggle on query loops in Bricks

How to add a layout toggle on query loops in Bricks

In this tutorial, we’ll show you how to change the layout of your query loop container based on the click of an icon toggle sitting…
Categories:
How to populate a map with dynamic markers from a CPT using ACF in Bricks (PART 1)

How to populate a map with dynamic markers from a CPT using ACF in Bricks (PART 1)

This tutorial provides the PHP & JS codes that can be pasted in order to create a dynamic map with markers populated from a custom…
Categories:
Pro
Previous Two Posts in Bricks Query Loop

Previous Two Posts in Bricks Query Loop

This Pro tutorial shows how we can modify the parameters of a Bricks query to limit the posts to the previous two whilst cycling to…
Pro
6 Random Featured Posts in Alphabetical Order in Bricks

6 Random Featured Posts in Alphabetical Order in Bricks

How to output x number of random posts with a specific meta value set, in Alphabetical order.
Categories:
Pro
Dynamic Horizontal Posts Accordion in Bricks

Dynamic Horizontal Posts Accordion in Bricks

Update on 8 Sep 2024: You may want to follow the newer version that considers accessibility. Looking to make a Horizontal Image Accordion dynamic? This…
Pro
Alternating Posts from Two Post Types in Bricks

Alternating Posts from Two Post Types in Bricks

How to output posts from two seperate post types, alternating in a query loop.
Categories:
Pro
Post Data for the Current User in Bricks with Meta Box

Post Data for the Current User in Bricks with Meta Box

How to configure a query loop to output the post data of the SalesRep CPT associated with the current user.
Categories:
How to show data of a post whose ID is the value of a URL parameter in Bricks

How to show data of a post whose ID is the value of a URL parameter in Bricks

In the Bricks Facebook group, a user asks: Hey Everyone,I am trying to create the following:1- I have a Custom Post Type2- I have a…
Categories:
Pro
ACF Post Object Query Loop inside a Posts Query Loop in Bricks

ACF Post Object Query Loop inside a Posts Query Loop in Bricks

How to loop through a CPT and within each post, output a list of related posts.
Categories: