<div class=“relatedPosts”>
<h4>Related Posts:</h4> <ul> {% assign maxRelated = 4 %} {% assign minCommonTags = 1 %} {% 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 %} <div> <li><a href="{{ site.baseurl }}{{ post.url }}">{{ post.title }}</a></li> </div> {% assign maxRelatedCounter = maxRelatedCounter | plus: 1 %} {% if maxRelatedCounter >= maxRelated %} {% break %} {% endif %} {% endif %} {% endfor %} </ul> </div>