Get 30% discount on lifetime membership by using BFCM2023 coupon.
Offer ends on 30th Nov 2023 at 11:59:59 PM UTC.

Current Post Has Parent – Conditional Single Template

In the Bricks Facebook group, a user asks:

Hey! Anyone achieved to assign template to CPT but only to child posts? I cant figure this one out, I read smth about template score assignment but didnt really understood it. Thanks a lot!!

This Pro tutorial provides the steps to apply one of two Bricks templates to single posts (of any post type) depending on whether that post has a parent or not.

To be able to set a parent item for your CPT item make sure "Page Attributes" support is added. If using ACF to create your post type:

Step 1

Create two Bricks templates named say "Single - Post has Parent" and "Single - Post does not have a Parent" of the type "Single".

Edit the templates and build them as needed.

Do NOT apply a template condition.

Step 2

Let's use the bricks/active_templates filter to programmatically set a template from the previous step to single posts of testimonial post type.

Add the following in the child theme's functions.php 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 all 250+ Bricks code tutorials with BricksLabs Pro