show actually related posts

This commit is contained in:
⧉ infominer 2020-11-29 22:13:01 -05:00
parent 95ab0fbd79
commit e3a3e6159c

View File

@ -66,28 +66,30 @@ layout: default
{% endif %}
</article>
{% comment %}<!-- only show related on a post page when `related: true` -->{% endcomment %}
{% if page.id and page.related and site.related_posts.size > 0 %}
<div class="page__related">
<h4 class="page__related-title">{{ site.data.ui-text[site.locale].related_label | default: "You May Also Enjoy" }}</h4>
<div class="grid__wrapper">
{% for post in site.related_posts limit:4 %}
{% include archive-single.html type="grid" %}
{% endfor %}
</div>
</div>
{% comment %}<!-- otherwise show recent posts if no related when `related: true` -->{% endcomment %}
{% elsif page.id and page.related %}
<div class="page__related">
<h4 class="page__related-title">{{ site.data.ui-text[site.locale].related_label | default: "You May Also Enjoy" }}</h4>
<div class="grid__wrapper">
{% for post in site.posts limit:4 %}
{% if post.id == page.id %}
{% continue %}
{% 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_category in page.categories %}
{% if post.categories contains this_category %}
{% 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 %}
{% include archive-single.html type="grid" %}
{% endfor %}
{% endfor %}
{% if n_posts > 3 %}{% break %}{% endif %}
{% endfor %}
{% if n_posts > 0 %}
</div>
</div>
</div>
{% endif %}
{% endif %}
</div>