14th Dec '23
/
0 comments

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

Related Tutorials..

Pro
Custom Dynamic Data Tags for ACF Field Label, Prefix and Suffix in Bricks

Custom Dynamic Data Tags for ACF Field Label, Prefix and Suffix in Bricks

Bricks lacks built-in dynamic tags for ACF field labels, prefixes, and suffixes. This tutorial shows how to add them using custom dynamic tags.
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
How to Insert Element(s) Between Query Loop Posts in Bricks

How to Insert Element(s) Between Query Loop Posts in Bricks

Update on 16 Aug 2023: Follow this tutorial instead. This Pro tutorial shows how we can insert a Div (or any custom HTML) after nth…
Pro
Conditionally Rendering an Element Outside the Loop based on Taxonomy Term in Bricks

Conditionally Rendering an Element Outside the Loop based on Taxonomy Term in Bricks

A user asks: Hiding element based on taxonomy I have an element in a footer that I want to hide if a page has a…
Categories:
Pro
Custom Dynamic Data Tags in Bricks

Custom Dynamic Data Tags in Bricks

With a 'Media' query loop, this tutorial shows how we can retrieve various attachment-specific properties inside of the loop.
How to List Your Posts Divided by Categories in Bricks

How to List Your Posts Divided by Categories in Bricks

In this tutorial, we'll learn how to display a list of posts divided by each category. The DOM tree Here is how I structured my…
Categories:
Pro
Primary Term Name and Link in Bricks when using Rank Math

Primary Term Name and Link in Bricks when using Rank Math

One of the features of the Rank Math SEO plugin is the ability to mark a term like category or product category as primary. See…