-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrelated_posts.html
37 lines (30 loc) · 1.02 KB
/
related_posts.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<div class="relatedPosts">
<h4>You May Also Like</h4>
{% assign maxRelated = 6 %}
{% assign minCommonTags = 2 %}
{% assign maxRelatedCounter = 0 %}
<ul>
{% 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 %}
<li>
<p><a href="{{ site.baseurl }}{{ post.url }}">{{ post.title }}</a></p><!-- {{ commonTags }} -->
</li>
{% assign maxRelatedCounter = maxRelatedCounter | plus: 1 %}
{% if maxRelatedCounter >= maxRelated %}
{% break %}
{% endif %}
{% endif %}
{% endfor %}
</ul>
</div>