Opens in a new tab
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 634 Bricks code tutorials with BricksLabs Pro

Related Tutorials..

Pro
“Truncate text to these many characters” Bricks Control

“Truncate text to these many characters” Bricks Control

Bricks provides a :<number> dynamic data tag modifier that can be used to limit the amount of text by the specified number of words. Ex.:…
Pro
x Number of Random Bricks Query Loop Items(s) to be Shown Every x Hours

x Number of Random Bricks Query Loop Items(s) to be Shown Every x Hours

Showing how to display one random row of a Meta Box group for an hour and then output another random row.
Removing Action/Filter Inside a Plugin’s Namespaced Class Constructor

Removing Action/Filter Inside a Plugin’s Namespaced Class Constructor

Recently worked with a friend figuring out how to remove/undo/cancel an add_action() line that's inside a plugin's constructor inside a PHP Class with the file…
Categories:
Tags:
Pro
Filtering a Bricks Terms query on Term archive pages

Filtering a Bricks Terms query on Term archive pages

On product category archives, how to show product type names but only those that the current product category has.