<div class=“related”>

<h4>{{site.data.settings.related-posts.title}}</h4>
{% assign maxRelated = 4 %}
{% assign minCommonTags =  1 %}
{% assign maxRelatedCounter = 0 %}
{% for post in site.posts %}
    {% assign sameTagCount = 0 %}
    {% assign commonTags = '' %}
    {% for category in post.categories %}
      {% if post.url != page.url %}
        {% if page.categories contains category %}
          {% assign sameTagCount = sameTagCount | plus: 1 %}
          {% capture tagmarkup %} <span class="label label-default">{{ category }}</span> {% endcapture %}
          {% assign commonTags = commonTags | append: tagmarkup %}
        {% endif %}
      {% endif %}
    {% endfor %}
    {% if sameTagCount >= minCommonTags %}
      <div class = "related-posts">
      <h5><a href="{{ post.url | relative_url}}">• {{ post.title  }}</a></h5>
      </div>
      {% assign maxRelatedCounter = maxRelatedCounter | plus: 1 %}
      {% if maxRelatedCounter >= maxRelated %}
        {% break %}
      {% endif %}
    {% endif %}
  {% endfor %}
</div>