This is a huge part of the Layout Builder update and what powers the Archive Mode. We don’t have videos or docs yet, so I wanted to provide a rough outline of how it works so you can start building things with the archive builder beta. For the sake of the notes below, Layout Elements are: Section, Row, Column, Grid, Cell, and Div
Overview
- A Looper Consumer is an element that begins consuming data from a provider.
- From the Customize tab of a Layout Element, turn on the Looper Consumer setting. Assuming you’re in the archive mode, your element will “consume” the next post from the WP query.
- Any child elements that use Dynamic Content will be referencing that post.
- A Looper Consumer can have Items set to One, Many, or All.
- One simply consumes the data.
- Many/All allow you to consume the data and cause the element to repeat.
- Using different combinations of single and repeating elements will allow you to create post loops where some posts are styled differently or output completely different content. For example:
- You could make a Row consume data once and use an entire column layout to feature your most recent post.
- Then you could add another Row and make the first Column consume data and repeat All to output the rest of the query items in a standardized format.
- A Looper Provider is a data source that elements can consume to begin a new context for Dynamic Content.
- If you’re in the archive mode of the Layout Builder, the main WordPress query is your top level Looper Provider. If you begin consuming data, you’ll be pulling elements off that list
- You can enable a new Looper Provider on any Layout Element.
- Using one of the included provider types, you can create a new data context. If you’re already inside a Provider, the one above will be paused until this element finishes rendering.
- We have no limit on query nesting, but it isn’t a great practice to have too many nested queries because you’re polling the database so many times.
I know this isn’t super descriptive/detailed but hopefully it’s enough to get you started. Try out some of the archive and WooCommerce starter templates to get a better idea of how it works.
Improvements
- Yes, we will be adding a way to filter the Query Builder by taxonomies
- We have a hook based looper provider working, where you can use a custom WordPress hook to supply data but it’s disabled at the moment because I’m not happy with how it could let people potentially trigger hooks in WordPress core or other plugins. Once we lock that down it could be a very interesting technique because you could even develop a way to source content remotely via APIs and pipe it into your designs.
- It might not be in this release, but we do plan to add a Looper Provider type to support ACF repeater fields (even nested repeaters).
Let us know if you have any questions or feedback on the feature!