Jekyll — Add Related Posts At The End Of A Post
At the end of a blog post, it’s a good idea to recommend similar posts to your readers. This helps them to find more great content on your website easily.
I used to manually add related posts at the end of each article but this became really tedious.
When I migrated my website from WordPress to Jekyll, this similar posts feature was a must-have for me. I wanted to make this process as automated as possible.
In this post, I want to share with you how I implemented a related posts section at the end of my blog posts on my Jekyll site.
File Structure
Let’s start by covering how the files are set up.
In the _layouts folder, I have an article.html. This is the template used by articles and it’s where the main code for this feature is implemented.
All I need to do is add the correct layout to any posts in the _posts folder.
I can do this by adding this to the file’s metadata:
---
layout: article
---
Logic
To build this functionality, I first decided how similar posts should be determined.
I wanted similar posts to be found based on the Tags associated with posts.