<div id=“relatedPosts”>
<h4>You may also like</h4>
{% assign maxRelated = 4 %} {% assign minCommonTags = 2 %} {% assign maxRelatedCounter = 0 %}
{% for post in site.posts %} {% assign sameTagCount = 0 %} {% assign commonTags = '' %} {% for tag in post.tags %} {% if post.url != page.url %} {% if page.tags contains tag %} {% assign sameTagCount = sameTagCount | plus: 1 %} {% capture tagmarkup %} <span class="label label-default">{{ tag }}</span> {% endcapture %} {% assign commonTags = commonTags | append: tagmarkup %} {% endif %} {% endif %} {% endfor %} {% if sameTagCount >= minCommonTags %} <a href="{{ site.baseurl }}{{ post.url }}" class="related_post"> <figure> <img src="{{absolute_url}}/img/img_dest/{{ post.img_dest }}" /> <legend>{{ post.title }}</legend> </figure> </a> {% assign maxRelatedCounter = maxRelatedCounter | plus: 1 %} {% if maxRelatedCounter >= maxRelated %} {% break %} {% endif %} {% endif %} {% endfor %}
</div>