# How to create a related posts section

**URL:** <https://talk.jekyllrb.com/t/how-to-create-a-related-posts-section/4867>\
**Category:** Help\
**Created:** [August 18, 2020, 2:15pm UTC](https://talk.jekyllrb.com/t/how-to-create-a-related-posts-section/4867 "2020-08-18T14:15:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nonso](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/nonso/32/2742_2.png) [@Nonso](https://talk.jekyllrb.com/u/Nonso)\
**Post date:** [August 18, 2020, 2:15pm UTC](https://talk.jekyllrb.com/t/how-to-create-a-related-posts-section/4867/1 "2020-08-18T14:15:03Z")

</div>

Am trying to create a set of related posts on my site. What is the best way to approach this. I have tried some methods I found online but some how it let’s my build failed. Jekyll related posts just literally the most recent posts as related,which isn’t what I want.

---

<div class="post-metadata">

**Author:** ![mmistakes](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/mmistakes/32/2169_2.png) [@mmistakes](https://talk.jekyllrb.com/u/mmistakes)\
**Post date:** [August 18, 2020, 4:19pm UTC](https://talk.jekyllrb.com/t/how-to-create-a-related-posts-section/4867/2 "2020-08-18T16:19:26Z")

</div>

Where are you hosting your site? If it’s with GitHub Pages then it will only show the latest posts and not “related” as LSI is disabled.

As per Jekyll’s docs:

> If the page being processed is a Post, this contains a list of up to ten related Posts. By default, these are the ten most recent posts. For high quality but slow to compute results, run the `jekyll` command with the `--lsi` ([latent semantic indexing](https://en.wikipedia.org/wiki/Latent_semantic_analysis#Latent_semantic_indexing)) option. Also note GitHub Pages does not support the `lsi` option when generating sites.

If you can install plugins there are ones that can improve the related posts by matching tags and such.

- [GitHub - toshimaru/jekyll-tagging-related\_posts: Jekyll `related_posts` function based on tags.](https://github.com/toshimaru/jekyll-tagging-related_posts)
- [GitHub - alfanick/jekyll-related-posts: Proper related posts plugin for Jekyll - uses document correlation matrix on TF-IDF (optionally with Latent Semantic Indexing)](https://github.com/alfanick/jekyll-related-posts)

And if you can’t install plugins there are pure Liquid methods that can do it, although they might increase your build time if you have a lot of posts.

- [Making Jekyll related posts really related! | Webjeda](https://blog.webjeda.com/jekyll-related-posts/)

---

<div class="post-metadata">

**Author:** ![jhvanderschee](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/jhvanderschee/32/583_2.png) [@jhvanderschee](https://talk.jekyllrb.com/u/jhvanderschee)\
**Post date:** [August 19, 2020, 8:39am UTC](https://talk.jekyllrb.com/t/how-to-create-a-related-posts-section/4867/3 "2020-08-19T08:39:39Z")

</div>

You can add tags to your page and then filter posts with a specific tag using the where\_exp filter.

frontmatter:

```
- tags: 
  - mytag
  - myothertag

```

layout:

```
{% for item in site.posts | where_exp: "post","post.tags contains 'mytag'" %}
  ...
{% endfor %}

```

Note that this is not really a related posts section… this is just a list of posts that have a specific tag.

---

<div class="post-metadata">

**Author:** ![Nonso](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/nonso/32/2742_2.png) [@Nonso](https://talk.jekyllrb.com/u/Nonso)\
**Post date:** [August 20, 2020, 8:37pm UTC](https://talk.jekyllrb.com/t/how-to-create-a-related-posts-section/4867/4 "2020-08-20T20:37:00Z")

</div>

Frankly I didn’t know about the LSI but the webjeda tuts got the job done. Thanks.

---

<div class="post-metadata">

**Author:** ![unfor19](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/unfor19/32/4106_2.png) [@unfor19](https://talk.jekyllrb.com/u/unfor19)\
**Post date:** [November 19, 2021, 10:33pm UTC](https://talk.jekyllrb.com/t/how-to-create-a-related-posts-section/4867/5 "2021-11-19T22:33:48Z")

</div>

Thank you for this. I’m using Jekyll v4.2.0 and [toshimaru/jekyll-tagging-related\_posts](https://github.com/toshimaru/jekyll-tagging-related_posts) works great.

In case you’re using `bundle install`, here’s my setup for [toshimaru/jekyll-tagging-related\_posts](https://github.com/toshimaru/jekyll-tagging-related_posts)

`Gemfile`

```ruby
group :jekyll_plugins do
  # Other plugins ...
  gem "jekyll-tagging-related_posts"
end

```

`_config.yaml`

```auto
plugins:
  # Other plugins ...
  - jekyll-tagging-related_posts

```

Install dependencies with `bundle install` and add the following snippet to your `post` layout.

`post` layout

```auto
<! -- 
Source toshimaru/jekyll-tagging-related_posts#usage
-->
{% if site.related_posts.size >= 1 %}
<div>
  <h3>Related Posts</h3>
  <ul>
    {% for related_post in site.related_posts limit: 5 %}
    <li><a href="{{ related_post.url }}">{{ related_post.title }}</a></li>
    {% endfor %}
  </ul>
</div>
{% endif %}

```
