Top-level Pages and Children Bricks Query Loop

This Pro tutorial for Bricks users can be considered Part 2 or a variation of the earlier Bricks Query Loop for Top-level Parent Pages with Children tutorial.

Given this Page structure:

The objective is to list all top-level Pages (not just parent Pages) in the outer query loop and the child Page(s) (if present) of the current Page being iterated from the outer loop in the inner query loop.

Like this:

Note: This tutorial works with any hierarchical post type, not just page.

Step 1

Let's first define a custom function to check if the current post has children.

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

Instant access to 390+ Bricks code tutorials with BricksLabs Pro