{% assign maxRelated = 4 %} {% assign minCommonTags = 1 %} {% assign maxRelatedCounter = 0 %} {% assign posts = site.posts | where_exp: "item", "item.slug != page.slug" %} {% if posts.size >= 1 %} {% for post in posts %} {% assign sameTagCount = 0 %} {% for category in post.categories %} {% if page.categories contains category %} {% assign sameTagCount = sameTagCount | plus: 1 %} {% endif %} {% endfor %} {% if sameTagCount >= minCommonTags %} {% comment %} {% increment my_counter %} {% endcomment %} {% if maxRelatedCounter == 0 %}

Related posts

{% endif %} {% assign maxRelatedCounter = maxRelatedCounter | plus: 1 %} {% if maxRelatedCounter >= maxRelated %} {% break %} {% endif %} {% endif %} {% endfor %} {% if maxRelatedCounter > 0 %}
{% endif %} {% endif %}