Skip to content

Filed under Statamic

Related Content Via Taxonomy Overlap in Statamic

How to build a related posts list by overlapping tags with the conditions parameter, without a third party plugin.

On my list of things to work on with my new Statamic based blog was the ability to show related blog posts based on tags. In ExpressionEngine, a tag feature requires a third party plugin from the start. In Statamic, flexible taxonomies come out of the box.

I looked through the documentation for instructions on how to show related entries based on taxonomy overlap but did not find what I thought I was looking for. A quick Twitter message later to Jack McDade gave me my answer: use the conditions parameter on the entries:listing tag. It turns out this very feature is in the London Wild theme that ships with Statamic.

Here is how I implemented the related posts feature on my blog. The opening tag sits inside the current template. At first I was cautious about putting it within a template that is already displaying entry content, but that is just because I am used to ExpressionEngine. In Statamic, there is no need for an entries:listing tag on detail pages. That happens automatically. Because of that, there is no problem with tags clashing.

The conditions parameter is where the magic happens. We set up one condition for tags and then feed it a list of all tags assigned to the current page entry content. The single curly braces allow the variable to be both set by the page but then accessed by other tags on the same page. Another condition prevents the current page from being displayed by excluding it by page URL.

You will also see a common ExpressionEngine technique for rendering opening and closing markup only at the proper position in a loop of results. If you are used to ExpressionEngine, you will feel right at home.

That is pretty much it. Tag overlap based related entries, listing out of the box in Statamic.