Update related posts

This commit is contained in:
agusmakmun
2016-04-19 16:22:55 +07:00
parent 7ea1661747
commit f3bca594ad
6 changed files with 34 additions and 5 deletions

View File

@@ -7,3 +7,32 @@ layout: default
<div class="content">
<div class="post">{{ content }}</div>
</div>
{% assign hasSimilar = '' %}
{% for post in site.posts %}
{% assign postHasSimilar = false %}
{% for tag in post.categories %}
{% for thisTag in page.categories %}
{% if postHasSimilar == false and hasSimilar.size < 6 and post != page and tag == thisTag %}
{% if hasSimilar.size == 0 %}
<div class="panel-body">
<h4>Related Posts</h4>
<ul>
{% endif %}
<li class="relatedPost">
<a href="{{ site.url }}{{ post.url }}">{{ post.title }}
{% if post.categories %}
(Categories: {{ post.categories | join: ', ' }})
{% endif %}
</a>
</li>
{% capture hasSimilar %}{{ hasSimilar }}*{% endcapture %}
{% assign postHasSimilar = true %}
{% endif %}
{% endfor %}
{% endfor %}
{% endfor %}
{% if hasSimilar.size > 0 %}
</ul>
</div>
{% endif %}