How To Filter Posts With Jekyll with Categories

Filtering posts can help you create better resources for visitors. Instead of having your blog posts spread out about a certain topic, you can filter through them with a categories tag.

First, you want to start off by writing the HTML/Liquid code it looks something like this:

 {% for post in site.posts %}
   {% if post.categories contains 'race-cars' %}
     <div class="blog-posts"> 

       <a href="{{ post.url | absolute_url }}">

  {% endif %} 
{% endfor %}

In order to make this work, you’re going to have to assign add the categories tag in your front matter at the top of each post

title: K24 Honda Civic
description: A little race car with a nice swap
categories: race-cars

For me this took way too long to learn, I spent hours trying to figure this out only to one day realize how easy it was.

Leave a Comment