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

Related Tutorials..

Pro
Posts Grouped by Month and Year in Bricks

Posts Grouped by Month and Year in Bricks

Nesting query loops with months & years in descending order, with the inner loop outputting the posts.
Categories:
Pro
Query Loop in Bricks

Query Loop in Bricks

This Pro tutorial walks you through the steps to use the Query Loop feature in Bricks to display a responsive grid of posts using CSS…
Categories:
Pro
Top-level Pages and Children Bricks Query Loop

Top-level Pages and Children Bricks Query Loop

This Pro tutorial for Bricks users can be considered Part 2 or a variation of the earlier Bricks Query Loop for Top-level Parent Pages with…
Categories:
Related Posts by Author in Bricks

Related Posts by Author in Bricks

Querying posts on single posts by the author of the current post.
Categories:
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
Displaying Gallery of SureCart Product Images with Bricks’ Query Loop

Displaying Gallery of SureCart Product Images with Bricks’ Query Loop

Custom query loop for looping through SureCart product images.
Categories:
Tags:
Pro
Nested Meta Box Query Loop Inside a CPT Query Loop in Bricks

Nested Meta Box Query Loop Inside a CPT Query Loop in Bricks

This Pro tutorial provides the steps for setting up a cloneable Meta Box group query inside a CPT query in Bricks. Scenario: CPT: course Meta…
Categories:
Pro
Adjacent Posts Bricks Query Loop

Adjacent Posts Bricks Query Loop

This Pro tutorial provides the steps to customize a posts query loop in Bricks to show previous and next posts on single post pages. The…
Categories: