minimal-mistakes: Related posts not shown

  • This is a question about using the theme.
  • I believe this to be a bug with the theme — not Jekyll, GitHub Pages or one of the bundled plugins.
  • This is a feature request.
  • I have updated all gems with bundle update.
  • I have tested locally with bundle exec jekyll build.

Environment informations

  • Minimal Mistakes version: 4.0.1 (feature/theme-gem branch)
  • jekyll gem version: 3.2.1 (master branch)
  • Operating system: Mac OSX 10.11.6

Expected behavior

Related post should appear on every post as they are enabled by default in my _config.yml:

# Defaults
defaults:
  # _posts
  * scope:
      path: ""
      type: posts
    values:
      related: true

Steps to reproduce the behavior

  1. create a couple of posts
  2. enable related posts on _config.yml

Additional information

If I insert the following code block (extracted from _layouts/single.html) in a post, the related posts are shown as expected:

{% if page.id and page.related and site.related_posts.size > 0 %}
  <div class="page___related">
    {% if site.data.ui-text[site.locale].related_label %}
      <h4 class="page__related-title">{{ site.data.ui-text[site.locale].related_label | default: "You May Also Enjoy" }}</h4>
    {% endif %}
    <div class="grid__wrapper">
      {% for post in site.related_posts limit:3 %}
        {% include archive-single.html type="grid" %}
      {% endfor %}
    </div>
  </div>
{% endif %}

Any ideas? Thanks in advance for any help!

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 27 (20 by maintainers)

Commits related to this issue

Most upvoted comments

I came up with a way of showing “related posts” by like post.tags instead of using the built in site.related_posts array.

The advantage here is you actually get a different set of related posts on each post instead of just the “most recent” posts that currently happens due to LSI being disabled on GitHub Pages.

Using this spaghetti code of Liquid in _layouts/single.html will display related posts that share the same tags as the current post. It will show 1-4 posts depending on how many matches it finds.

 {% comment %}<!-- show posts by related tags when `related: true` -->{% endcomment %}
  {% if page.related %}
    {% assign n_posts = 0 %}
    {% for post in site.posts %}
      {% if post.id == page.id %}{% continue %}{% endif %}
      {% for this_tag in page.tags %}
          {% if post.tags contains this_tag %}
            {% if n_posts == 0 %}
              <div class="page__related">
                {% if site.data.ui-text[site.locale].related_label %}
                  <h4 class="page__related-title">{{ site.data.ui-text[site.locale].related_label | default: "You May Also Enjoy" }}</h4>
                {% endif %}
                <div class="grid__wrapper">
            {% endif %}
            {% include archive-single.html type="grid" %}
            {% assign n_posts = n_posts | plus: 1 %}
            {% break %}
          {% endif %}
      {% endfor %}
      {% if n_posts > 3 %}{% break %}{% endif %}
    {% endfor %}
    {% if n_posts > 0 %}
        </div>
      </div>
    {% endif %}
  {% endif %}

Thoughts?

I’ve been against adding more configuration flags as they have many costs. In this case I don’t think it’s warranted as you can override the two files above as I have in the PR if you’re OK with slower builds.