Posted on by

Placing a Category Link on a Category Field Value

This tutorial is for a setup where, when a record is displayed, certain terms will have a link placed on them that will show all the records that have the same value.

For the purpose of this tutorial, I’m calling such a field a “category field” because the value defines a category that the record belongs to. For example, a “state” field could have a link placed on it that would, when clicked, provide a list of all the records with the same value for the “state” field.

How these category links work is explained in this article: Creating Links to Show a Filtered List Result

A Custom Template

To do this, we need to use a custom template that looks for a category field and places the link on the field if it finds it.

In the template, near the top, are the two values you will need to set this up for your specific needs. $category_fields is an array of field names for the fields you want the category link placed on.

Note that not all fields will work for this: dropdowns, radio button and checkboxes are good choices. This won’t work on a multiselect field.

In this example, we chose two fields to put the link on: a field named “category” and the “state” field. In the single record display, if the user clicks on the name of the state, they will be taken to a page that shows all the records from that state. Same for the category field.

$list_page provides the name of the page where you want the category to be shown. This can be your regular participant list page, or it can be any page with the [pdb_list] shortcode on it.

Installing the Template

Download the template, edit it to set up the links on the fields you want, then upload the template to a safe location. On your single record page, set the shortcode to use the custom template like this:

[pdb_single template=category-link]

It’s also possible to set up these links in the list shortcode, it works the same way, you just have to put the code that checks for the field into the loop after the $this->the_field(); statement.

You can download the template by clicking on the file link at the bottom of the code window.

Leave a Reply
You have to agree to the comment policy.

Would you like to be notified of followup comments via e-mail? You can also subscribe without commenting.

Leave a Reply
You have to agree to the comment policy.

Would you like to be notified of followup comments via e-mail? You can also subscribe without commenting.