Condition for Checking Current Post Category in Bricks

In the Bricks Facebook group, a user asks:

I have two post categories – press release and news.
I want to put a condition in the single post template to show/hide a certain block/element on a specific category. How should I do this?

The built-in way to do this is using the Dynamic data condition like this:

{post_terms_category}

outputs the HTML of links to current post’s categories separated by commas.

In this case we want to append the :plain filter

{post_terms_category:plain}

In the last input field, we would have to type/paste the name of the category we want to check.

To NOT render the element when the post has a specific category, use does not contain instead of contains.

The other easier way is to use the Post category condition of our BricksExtras. With this condition you don’t have to type the name of the category and simply select one from the dropdown.

Get access to all 526 Bricks code tutorials with BricksLabs Pro

Leave the first comment

 

Related Tutorials..

Render an element having a specific HTML ID based on value of a custom field

Render an element having a specific HTML ID based on value of a custom field

This tutorial provides the steps to use Bricks' bricks/element/render filter to conditionally output an element that has the specified HTML ID based on the value…
Categories:
Pro
How to Insert Element(s) Between Query Loop Posts in Bricks

How to Insert Element(s) Between Query Loop Posts in Bricks

Update on 16 Aug 2023: Follow this tutorial instead. This Pro tutorial shows how we can insert a Div (or any custom HTML) after nth…
How to conditionally load your scripts based on an ACF field

How to conditionally load your scripts based on an ACF field

This tutorial provides the PHP codes that can be pasted in order to enqueue your scripts conditionally based on the value of an ACF field…
Categories:
[Function] Current Term Has Children

[Function] Current Term Has Children

Updated on 20 Jul 2024 A user asks: I'm working on an archive template for WooCommerce products. I'm trying to hide a section if there…
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
Showing a Popup conditionally in Bricks based on Query Parameter

Showing a Popup conditionally in Bricks based on Query Parameter

Here's two ways a Bricks Popup can be shown on page load depending on URL parameter value.
Categories:
Tags:
Pro
Custom Conditions in Bricks Builder

Custom Conditions in Bricks Builder

Updated on 22 Jun 2022 This Pro tutorial is a continuation of the previous Conditions in Bricks Builder tutorial. We are going to keep updating…
Categories: