24th Jun '22
/
3 comments

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 Grid while reducing the load on the database using a Bricks filter hook.

For each post we are going to set up:

  • featured image in a custom image size linking to post's permalink
  • post title linking to permalink
  • post excerpt
  • Read more button linking to permalink

We shall also ensure that the Read more button is positioned at the end (vertically) of each post.

This example is mainly meant for secondary queries where a fixed number of posts (6 in this case) are to be shown.

Step 1

Edit your Page with Bricks.

Posts Grid Query Loop Section

You can skip this entire step and simply import the Posts Grid Query Loop Section file from our test site if you want. This is provided near the end of this step.

If you want to get familiar with Bricks and learn and ins-and-outs, we recommend doing it manually as detailed below.

Add a Section. In Bricks version 1.4.0.2 and earlier, this is done by clicking the + icon, then the Layout icon (on the Container element) and clicking on "Full width (Section)".

This adds a Section having a Container.

Select the Container and add a Heading element.

You may want to change the text to something like "Latest Posts".

Add a Container below the heading. This will be the parent container of all the posts. You might want to double click on the layer name in the structure panel and rename it to something like "Posts Grid".

Let us add a bit of custom CSS for an automatic (no need to set breakpoint-specific CSS using media queries) responsive grid.

STYLE → CSS → Custom CSS:

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..

Latest Featured Posts First in Bricks Query Loop (No Duplicates)

Latest Featured Posts First in Bricks Query Loop (No Duplicates)

In the Bricks Facebook group a user asks: We can use AI to help unfreeze our brains sometimes or at least have it write the…
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:
Pro
Search Results Grouped by Post Types in Bricks

Search Results Grouped by Post Types in Bricks

Updated on 08 Oct 2024 This Pro tutorial provides the steps to arrange the search results by specified post types in a Bricks site. We…
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
Posts Grouped by Taxonomy Terms in Bricks using BricksExtras’ Dynamic Table and Pro Tabs

Posts Grouped by Taxonomy Terms in Bricks using BricksExtras’ Dynamic Table and Pro Tabs

How to output any post type, with the taxonomy terms as Tab titles and posts inside tables with sortable columns.
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
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…