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

Related Tutorials..

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.
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
ACF Repeater sub field value dynamic data condition in Bricks

ACF Repeater sub field value dynamic data condition in Bricks

This Pro tutorial provides the steps to output an element on single posts (can be of any post type) only if a specified ACF (Pro)…
Conditionally Outputting Elements only for Posts that have a Specific Taxonomy Term

Conditionally Outputting Elements only for Posts that have a Specific Taxonomy Term

Using the core WordPress has_term() function for checking if the current post has a specific term of a given taxonomy.
Categories: