Media File Attachment Data in Bricks

Updated on 15 Aug 2024

With a query loop of type Posts and Post Type of "Media", it is possible to output post-specific images (or files or any other attachment types allowed in WordPress Media Library) like the attached images for posts or ACF Gallery field images for building custom galleries in Bricks.

This Pro tutorial shows how we can retrieve these attachment-specific properties:

  • ID
  • Alternative Text
  • Title
  • Caption
  • Description
  • File URL

These can be used inside the query loop enabled-block for dynamic media items listing/grids in Bricks.

Step 1

Ensure that your query type is set up like this:

Step 2

Add the following in child theme's functions.php (w/o the opening PHP tag) 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 524 Bricks code tutorials with BricksLabs Pro

Related Tutorials..

Pro
Conditional Output Based on ACF Date Field in Bricks

Conditional Output Based on ACF Date Field in Bricks

Updated on 1 Aug 2024 Looking to have a Section or other elements in Bricks rendered on the frontend only if today's date is before…
Categories:
Pro
“Pro” Category Ribbon for Posts in Bricks

“Pro” Category Ribbon for Posts in Bricks

This Pro tutorial provides the steps to show a "Pro" ribbon for posts that are categorized under the "Pro" category when using Bricks builder. Step…
Categories:
Pro
Condition to Check if the Current Category Has At Least One Child

Condition to Check if the Current Category Has At Least One Child

Looking to render an element in the category archive Bricks template only if the category of the current category archive page is a parent? This…
Categories:
Dynamic Data :value filter in Bricks

Dynamic Data :value filter in Bricks

Bricks 1.5.7 introduced a new :value dynamic data filter. This tutorial provides a practical example of how this filter can be used. Meta Box Checkbox…
Categories:
Month-based Background Image in Bricks

Month-based Background Image in Bricks

How to have different background images for an element for different quarters in a year.
Categories:
Weekday Condition in Bricks

Weekday Condition in Bricks

As of Bricks 1.7, the built-in "Weekday" condition does not work correctly. This is most likely due to it not taking the site's timezone (set…
Categories: