12th Jan '24
/
2 comments

Conditional Posts page template in Bricks

Updated on 15 Apr 2024

In the Bricks Facebook group a user asks:

Archive Template Layout based on ACF ValueHi guys, do you have an idea how set up the following scenario:I want to use Bricks in combination with ACF Pro.Based on an ACF value which you can change on an Options Page created with ACF Pro, I want to change the used Archive Template for my blog posts.E.g. Today, I choose Option 1 and all blog archives are black. Tomorrow I choose Option 2 and everything is white…I just can't figure out how to set a bricks template condition for that scenario that it will take the ACF field into consideration.What I want to prevent is to have all different layouts in one Bricks Template and only show the respective one (based on the setting) and hide all the others?

This Pro tutorial for Bricks users provides the steps to apply a template chosen in ACF Pro's options page to the blog posts index page, also known as the Posts page using bricks/active_templates filter.

example.com/blog:

With

for example,

While this tutorial is written for ACF Pro, it should also work when using other custom fields plugins like Meta Box with minor changes. If you need any help or guidance with this, please leave a comment.

Step 1

Create a Page titled "Blog" or "News".

Set it as the Post page at Settings → Reading.

Step 2

At Bricks → Templates, create two templates of the type "Archive".

Edit each with Bricks and add your desired elements like a heading text and Posts element or a query loop.

Do not apply template conditions.

Step 3

Install and activate ACF Pro.

Go to ACF → Options Pages and create a new Options page.

Step 4

Create a corresponding field group.

Field type: Button Group

Field label: Blog Posts Index Layout

Field Name: blog_posts_index_layout

Choices:

273 : Layout 1274 : Layout 2

Replace 273 with the ID of your Layout 1 template and 274 with that of your Layout 2 template.

Step 5

Click on "Site Settings" in the admin menu, select your desired layout and click Save/Update.

Step 6

Add the following in child theme's functions.php (omit the beginning PHP tag if going this route) 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 633 Bricks code tutorials with BricksLabs Pro

Related Tutorials..

Pro
Programmatically populating ACF field values in WordPress

Programmatically populating ACF field values in WordPress

An example of how to set the values of a Select-type field with the names and labels of all public post types.
Categories:
Show Product Categories Count Using Bricks Filter Hook

Show Product Categories Count Using Bricks Filter Hook

Unable to find terms count from the Dynamic Data provided by Bricks theme? It's okay, this simple tutorial shows you how to properly get the…
Categories:
Tags:
Pro
Filtering Meta Box Cloneable Group by Select Subfield for Multiple Bricks Query Loops with Conditional Output

Filtering Meta Box Cloneable Group by Select Subfield for Multiple Bricks Query Loops with Conditional Output

In the Bricks Facebook group a user asks: Consider this cloneable Meta Box field group for a Custom Post Type called Tour: with the Tour…
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…