{% assign cat = page.categories[0] %}
{% assign cat_list = site.categories[cat] %}
{% for post in cat_list %}
{% if post.url == page.url %}
{% assign prevIndex = forloop.index0 | minus: 1 %}
{% assign nextIndex = forloop.index0 | plus: 1 %}
{% if forloop.first == false %}
{% assign next_post = cat_list[prevIndex] %}
{% endif %}
{% if forloop.last == false %}
{% assign prev_post = cat_list[nextIndex] %}
{% endif %}
{% break %}
{% endif %}
{% endfor %}
{% if prev_post or next_post %}
{% else %}
{% endif %}