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

Get access to all 526 Bricks code tutorials with BricksLabs Pro

Related Tutorials..

Pro
Conditional single post Bricks template based on internal referrer URL

Conditional single post Bricks template based on internal referrer URL

How to automatically select a single post template depending on the page from which the post is accessed.
Pro
Setting a Bricks template for Parent pages

Setting a Bricks template for Parent pages

This Pro tutorial shows how bricks/active_templates filter can be used to programmatically assign a Bricks template to all singular pages (of any post type) that…
Pro
Conditional Single CPT Templates based on Post Hierarchy in Bricks

Conditional Single CPT Templates based on Post Hierarchy in Bricks

In the past we covered Conditional Bricks Templates Based on Product Category Hierarchy Levels in Bricks. This Pro tutorial provides the steps to programmatically apply…
Pro
Dynamic Post-specific Templates in Bricks using Meta Box/ACF Select Field

Dynamic Post-specific Templates in Bricks using Meta Box/ACF Select Field

Update on 23 Aug 2023: Added steps for ACF. Bricks builder v1.8.4 introduced an pretty useful filter called bricks/active_templates that flew under the radar. This…