Menu
All plugins

Card Listings for Bricks

Build a card once as a Bricks template, save a query for the content you want, and Card Listings for Bricks turns the pair into a listing you can place anywhere, with a Bricks element or a shortcode. One card design can feed many listings, and a listing can switch to a different card for records that match a rule.

Version: 1.0.0-rc21 (release candidate, for staging) · Requires: WordPress 6.2+, PHP 7.4+, Bricks (for rendering). ACF is optional. · See the live demo · Variants and page numbers

What it does

  • Adds a Card Listings menu to the admin with Listings, Query Presets, a Field Explorer and Import / Export.
  • A listing joins a Bricks card template, a content type and, optionally, a query preset and some card rules.
  • A query preset is a saved, safe query that you set up with drop-downs: content type, items per page, sort order, one taxonomy term and one custom field condition. There is no raw SQL or PHP.
  • Renders every item with the card template you chose, so the card is ordinary Bricks content with ordinary dynamic data, such as the title, link, date, excerpt, featured image and ACF fields.
  • Card rules pick a different card for a record by its position in the listing, its featured image or a custom field.
  • Shows server-rendered, numbered pagination that works without JavaScript. Every listing on a page pages on its own.
  • Can load pages in place with AJAX, if you switch it on. The page links stay real links.
  • Shows a friendly message when a listing has no results.
  • Every piece of admin text is translatable (text domain card-listings-for-bricks).
  • Adds a Card Listings element to Bricks (General group) and a shortcode.
  • The Field Explorer (administrators only) lists the custom field keys of a content type, from up to 20 published posts plus any ACF field group definitions. Presets and rules already offer those keys in their drop-downs.
  • Exports the configuration as JSON and imports it back as drafts. Both are for administrators only.

Installation

  1. Upload and activate the plugin. Bricks must be active to render a listing. The admin screens work without it, and a notice tells you when Bricks is missing.

Quick start

  1. In Bricks, open Templates and create a template for one card. Use dynamic data such as Card Listings for Bricks, and . Publish it.
  2. Optional: open Card Listings, Query Presets and add a preset. Leave a field empty to ignore it.
  3. Open Card Listings, Listings and add a listing. Choose the card template, the content type and the preset. Publish it.
  4. In the Bricks editor add the Card Listings element and pick the listing. Or put on a page, with your listing’s ID.
  5. The plugin adds no layout styles, so give the cards a grid. See Styling below.

Listing settings

  • Bricks card template — the template used for each item. The template must be published.
  • Content type — any public content type. This always decides what is listed, even if the preset names another type.
  • Query preset — optional. Without one the listing shows 12 published items of the content type, newest first.
  • Preview record ID — a record to preview.
  • Card rules — optional. Each rule is a row that reads like a sentence: Use [a card] when [a field] [a condition]. Pick the card from a list, then pick what to test: Position in the listing (is the first item, is odd, is even, is number, or repeats every N starting at M), Featured image (is set or is not set), one of the custom fields found on your content (ACF fields appear with their labels), or Another custom field if you want to type a key. Field conditions are is equal to, is not equal to, has a value, is empty, is greater than, is less than and contains. Rules are checked from the top and the first match wins. Use the arrows to reorder and the cross to remove. A record that matches no rule gets the card chosen above. A custom field that holds a list, such as a gallery or a repeater, never matches, and the greater-than and less-than conditions need numbers on both sides. Up to 100 rules. Positions count across all pages, so for a repeating layout use a page size that is a multiple of the repeat, such as 6 or 9 for every 3.

Preview

The listing’s edit screen has a Preview box under the settings. It shows a snapshot of the saved listing (the first 12 items) using your real Bricks card styles, so save your changes and press Refresh to see them. The Show menu offers In page for each published page that already contains the listing (as the Bricks element or the shortcode), which loads that page so you see the real grid, card sizes and pagination, and Basic grid, a plain grid of the first 12 items with 1 to 4 preview columns, which is the only option for a listing that is not placed anywhere yet and also previews drafts. Switch between Desktop, Tablet and Mobile widths, or press Expand to open it as a large modal (Esc closes it). Site consent banners and popups are kept out of the preview. The Basic grid address is private to people who can edit the listing and expires with the page.

Query preset settings

A preset is a form of drop-downs, so nothing has to be typed from memory.

  • Content type — any public content type — and Items per page (1 to 100, default 12).
  • Sort by — date published, title, date modified, menu order, random, custom field (text) or custom field (number) — and a direction, ascending or descending.
  • Only show items in — pick a taxonomy that belongs to the content type, then one of its terms. The term list is filled in from the taxonomy you pick (the first 300 terms).
  • Only show items where — pick a custom field from those found on your content (ACF fields show with their labels) or Another custom field to type a key, then a comparison: is equal to, is not equal to, is greater than, is less than, is at least, is at most, contains, does not contain, has a value or has no value. The same field is used when you sort by a custom field.

Only published items are listed. Password-protected items are skipped.

More query preset options

  • The term of the page being viewed (term drop-down) — the listing follows the category or term archive it is placed on, children included. Elsewhere it is empty.
  • Whatever the page being viewed belongs to (taxonomy drop-down) — the same idea for any taxonomy.
  • Sort field — an optional field to sort by, independent of the field used in Only show items where.
  • {today} — type {today} or {today:FORMAT} as a custom field value to compare with today. Number-like values compare as numbers.
  • Leave out items where — a field and value to exclude. Items without the field are kept.
  • Also include — add a second content type to the same listing.
  • Any content type — list every public content type, which is what a site search needs.
  • Search — match the listing against the page’s search term (?sq=, or ?s= on a search page).

The element and the shortcode

The Bricks element has seven settings: the Listing, a Maximum items override (1 to 100), Hide pagination, Load pages without reloading, Use the current archive, Page links use /page/2/ and a Message when there are no results. The shortcode takes these attributes:

  • id — the listing’s ID. It must be a published listing.
  • limit — items per page, overriding the preset (1 to 100)
  • page — force a page number. Normally the page comes from the address.
  • pagination — no hides the page links and shows only the first page. Useful for a fixed mosaic or a teaser of the latest items.
  • empty — the message to show when there are no results. The default is “Nothing to show yet.” The bcl_empty_message filter can change it too.
  • ajax — yes loads pages in place (see Pagination). The default is no.
  • archive — yes shows the posts of the category, tag, author, date, search or blog page the listing is placed on, using that page’s own query, page size and page links. The listing’s own content type, preset and maximum are ignored, and AJAX paging is off.
  • path — yes makes page links clean /page/2/ addresses on archive and blog pages, instead of a ?bcl_page query.
  • key — names the page argument. Only needed when the same listing appears twice on a page.
  • preview — for people who can edit the listing. Shows one record, even a draft or private one, to check how a card looks.

Filters and counts

Visitors can narrow a listing with the Card Listings filters element. Place it anywhere on the page, choose the Listing it controls, and it shows a keyword box and a drop-down of terms. It sets ?bq= (keyword) and ?bt= (term) on the address, so filtered pages can be linked and bookmarked. Its settings are Listing, Keyword label, Keyword placeholder, Drop-down label, the “All” choice text and the Clear link text.

To show how many items a listing matches, use the dynamic tag {bcl_count:LISTING_ID} in any Bricks text, or the shortcode 0. The count follows the visitor’s filters.

Pagination

When a listing has more than one page, it adds a numbered list of links under the cards. Each listing has its own address argument, bcl_page_ followed by the listing’s ID (the Bricks element uses its element ID), so two listings on one page turn pages independently and each page is a real link that works with no JavaScript. Long lists are windowed, for example 1 … 73 74 75 76 77 … 153, so a thousand records do not print a hundred links. A page number past the end shows the last page. The pagination is not shown in a preview.

Loading pages in place

Switch on Load pages without reloading in the element, or add ajax="yes" to the shortcode. The page links stay ordinary links, so a listing still works without JavaScript, a link can be opened in a new tab or shared, and a search engine can follow it. With JavaScript on, a plain click fetches that page in the background and swaps only the listing and its page links. The address bar updates, Back and Forward work, focus moves to the listing, and the page scrolls back to the top of the listing only if it was out of sight. Card styles that Bricks adds for the new cards are merged in, Bricks element scripts are run again for them, and the listing fires a bcl:updated event for your own scripts. A bcl-loading class sits on the listing while a page loads. If anything goes wrong, the browser simply follows the link. The server sends the whole page and the script keeps only the listing, which is as heavy as a normal page view but needs no extra endpoint, so it works with the same caching as the rest of the site. Other listings on the page keep their own page.

Styling

The plugin has no stylesheet. Each listing is a .bcl-listing element, and also .bcl-listing-123 with the listing’s ID. Inside it each item is a .bcl-card with a data-bcl-post attribute that holds the item’s ID. The pagination is a nav.bcl-pagination with links, and the current page is a span.bcl-page-current. An empty listing holds a p.bcl-empty. A responsive grid is one rule:

.bcl-listing { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 16rem), 1fr)); gap: 2rem; }

Because the cards are direct children of the listing, layout rhythms are plain CSS too. These two are on the live demo:

  • Full width, then two, repeating: use a two column grid and .bcl-card:nth-child(3n+1) { grid-column: 1 / -1; }
  • A mosaic: use a four column grid with fixed row heights, then .bcl-card:first-child { grid-column: span 2; grid-row: span 2; } and .bcl-card:last-child { grid-column: span 2; }

The card itself is styled in the Bricks template. If you place the Card Listings element in a flex container, give it a width of 100%, or the grid will only be as wide as its content.

How it works

  • The listing builds a normal WordPress query from the preset and runs it on the server.
  • The items are rendered through a Bricks query loop, the same mechanism as a Bricks Query Loop element. Each item is the current post for its card, so every dynamic tag reads that item and not the page the listing sits on, and Bricks gives the cards class-based hooks instead of repeated element IDs. If the loop cannot run, each card is rendered on its own with the official shortcode.
  • For each item a card template is picked using the variant rules.
  • Each card is wrapped in a .bcl-card element. A template that is already being rendered is not rendered inside itself, and nesting stops after four levels.
  • Saving needs the right edit capability and a nonce. Import and export need manage_options and a nonce. Imported values are cleaned, and imports always arrive as drafts.

Not included

  • No Bricks Query Filter integration. Filtering is limited to the keyword and term controls of the Card Listings filters element, and only paging loads in place.
  • Import and export carry the configuration only. Template IDs are not remapped, so check the card template and the preset of every imported listing before you publish it.
  • Only Bricks 2.4.3 has been tested, because older Bricks releases are not available to test with. The plugin works with Bricks only, by design. Test your own dynamic tags on a staging site before using it in production.

Tested

This playground runs Bricks 2.4.3 and WordPress 7.1. On it the listings were checked for per-card dynamic data (title, link, date, excerpt, featured image, taxonomy terms and an ACF image field), a Card Listings element inside a Bricks Terms query loop, the shortcode in a normal page body, two independently paginated listings, the empty state, and a card template or preset that no longer exists. Twenty-two cards render in about a tenth of a second here. On a copy of the content grown to 1,222 posts (temporary posts, since removed), an 8 per page listing rendered in 70 to 140 ms per page, from page 1 to page 153. Placed on a category archive, the listing ignored the archive’s own query and showed its own preset. Cards carry no repeated element IDs. The same fixture (11 posts, 8 per page, a card with a dynamic title) was also run on clean installs of WordPress 6.2 (the stated minimum) and 7.1.3, each as a single site and as a multisite network with the plugin network-activated, on the main site and a subsite, with Bricks 2.4.3 and PHP 8.3. Page 1 and page 2 cards, distinct titles, no card IDs, the empty state and the pager (including subdirectory addresses) all passed, over the command line and over HTTP. The code also parses as PHP 7.4. For the 1.0.0-rc10 build, the same WordPress 6.2 single site and WordPress 7.1.3 multisite checks were repeated, and a 1,212 post copy of the content rendered pages 1, 2, 75 and 150 in 18 to 46 ms each, with a page number far past the end showing the last page. The query preset form was saved and read back in a browser (content type, sort, taxonomy and term, and a mixed-case custom field with NOT LIKE), the card rules rows were measured so every column lines up, and AJAX paging was run in a browser with a real Back and Forward trail and no page reload, with no console errors. It was also run on the live variants demo here, with its Bricks card styles.

Layout recipes

A last card that would sit alone in a row can fill it. For a two column grid: .bcl-card:last-child:nth-child(odd) { grid-column: 1 / -1; }. For three columns, use a six column grid with every card spanning two, then .bcl-card:last-child:nth-child(3n+1) { grid-column: span 6; } and .bcl-card:nth-last-child(2):nth-child(3n+1), .bcl-card:last-child:nth-child(3n+2) { grid-column: span 3; }. For cards with a 3:2 image, set aspect-ratio: 3 / 2 on the card.

Removing it

Deactivate and delete the plugin. Your listings and presets stay in the database, so reinstalling brings them back. Take a database backup before you delete them by hand.

Changelog

  • 1.0.0-rc21 — Later /page/N/ pages of a listing no longer 404 on blog and static pages.
  • 1.0.0-rc20 — Optional clean /page/N/ page links.
  • 1.0.0-rc19 — Any content type listings, search matching, and visitor filters with the Card Listings filters element.
  • 1.0.0-rc18 — {bcl_count:ID} tag and 0 shortcode.
  • 1.0.0-rc17 — Whatever the page belongs to (any taxonomy), and an optional sort field.
  • 1.0.0-rc16 — Term of the page being viewed, {today} comparisons, and Leave out items where.
  • 1.0.0-rc15 to rc11 — Use the current archive, a fix for the focus outline after AJAX paging, card styles applying on the front end, and admin styles moved to their own file.
  • 1.0.0-rc10 — Optional AJAX pagination. Query presets now use drop-downs. Card rule rows stay aligned when a custom field key is shown. All admin text is translatable.
  • 1.0.0-rc9 — Password-protected posts are no longer listed. A listing inside another Bricks loop no longer disturbs it. A page number past the end shows the last page. The preview’s page lookup is cached. Field Explorer is for administrators only.
  • 1.0.0-rc8 — Preview box on the listing edit screen, with device widths, an In page view that shows the listing on a real page with its real layout, a Basic grid view, and an expand-to-modal view.
  • 1.0.0-rc7 — New card rules builder: rows of “Use [card] when [field] [condition]” with drop-downs, reordering, and a position test (first, odd, even, number, or every N). Replaces the pipe-separated text box. Existing rules, imports and exports keep working.
  • 1.0.0-rc6 — Variant rules can choose a card by position, with @position, so a rhythm such as full width, then two, can use a different card design for each.
  • 1.0.0-rc5 — Long pagers are windowed with gaps, so very large listings stay usable.
  • 1.0.0-rc4 — Renamed from Bricks Card Listings to Card Listings for Bricks (shortcode , prefix bcl). Cards render through a Bricks query loop, which removes repeated element IDs. Helper CSS for filling an orphaned last row.
  • 1.0.0-rc3 — Each listing paginates on its own address argument, so listings on one page no longer change page together. A message shows when there are no results. New pagination, empty and key shortcode attributes, with matching element settings.
  • 1.0.0-rc2 — Each card now reads its own post on the front end. In rc1 the dynamic tags in a card read the page the listing was on, so every card showed the page’s title, date and image.
  • 1.0.0-rc1 — Release candidate. Server-rendered numbered pagination, a preview shortcode, template recursion protection, and checks on the listing, preset and content type before a query runs. JSON import as drafts and export for administrators only.