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.

Instant access to 390+ Bricks code tutorials with BricksLabs Pro

Leave the first comment