Conditional Related Posts in Bricks

This Pro tutorial provides the steps to output a section having the Related Posts element only if there is at least 1 related post for the current single post being viewed in Bricks.

We shall define a custom function that returns the count of posts that have the same tag or category as the current post and use that with Brick's echo dynamic data.

Then use that function to output a Section Template (having the "Related Posts" element) dynamically in the single Post Template if the count is greater than 0.

Step 1

Add the following in your child theme's functions.php or a code snippets plugin like WPCodeBox:

This is a BricksLabs Pro tutorial.

For full access login below or create your BricksLabs Pro account

Instant access to 390+ Bricks code tutorials with BricksLabs Pro