Customizing Category Display in Bricks

Bricks has a post_terms_category dynamic data tag that outputs comma-separated links of categories for the current post.

It also has a Taxonomy element that outputs an unordered list of the linked terms of the specified taxonomy which can be used to show the post's categories.

What if you want to output only the top-level (not necessarily parent) categories i.e., categories that aren't child categories?

This Pro tutorial provides two ways to limit the categories to top level ones.

  • extend the Taxonomy element as a new element
  • create a custom function based on the one in Bricks and using its dynamic data tag

Custom Taxonomy element

Step 1

If the Bricks child theme is not active already, upload and activate it.

Copy/duplicate

/wp-content/themes/bricks/includes/elements/post-taxonomy.php

as

/wp-content/themes/bricks-child/elements/custom-post-taxonomy.php

Step 2

Edit the custom-post-taxonomy.php file.

Change

class Element_Post_Taxonomy extends Element {

to

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