find related posts with category
{% for post in site.related_posts limit:5 %}
{% assign match = false %}
{% for category in post.categories %}
{% if page.categories contains category %}
{% assign match = true %}
{% endif %}
{% endfor %}
{% if match %}
<li><a href="{{ post.url }}">{{ post.title }}</a></li>
{% endif %}
{% endfor %}
since site.related_posts limited by 10, using site.posts instead of site.related_posts as you wishes
@see: filter site related posts in jekyll
fency code block with raw tag
when running locally, if you included liquid template syntax like {% %} or {{ }}, just remember to embrace them with raw tag: {% raw %} ... {% endraw %}, or your code block would accidently broken.
@see: mojombo/jekyll#814
reference: