Short version:
I want to add 1 to a number in a liquid template and use the result as an array index.
{% capture plus_one %}{{ 0 | plus: 1 }}{% endcaptur
I don't know if jekyll has changed since the accepted answer but I had to make a couple of changes to get it to work. According to the jekyll variables documentation there isn't a page.category, only a list of page.categories. In my site I only use one category per post so getting the first one works for me. If you use multiple categories per post you'll have to tweak this. Also I've run into issues because my categories are capitalized so I added the downcase. And finally, in my config.yml I am using url not baseurl. Hopefully this helps other people because this was the easiest way I found to add prev/next links by category to all posts.
{% for category in site.categories %}
{% assign catg_name = category.first %}
{% if catg_name == page.categories.first | downcase %}
{% assign catg_posts = category.last %}
{% endif %}
{% endfor %}
{% for post in catg_posts %}
{% if post.title == page.title %}
{% unless forloop.last %}
{% assign next = catg_posts[forloop.index] %}
←{{ next.title }} |
{% endunless %}
{% unless forloop.first %}
| {{ prev.title }}→
{% endunless %}
{% endif %}
{% assign prev = post %}
{% endfor %}