Skip to content

Instantly share code, notes, and snippets.

@opattison
Last active December 20, 2015 21:39
Show Gist options
  • Save opattison/6199158 to your computer and use it in GitHub Desktop.
Save opattison/6199158 to your computer and use it in GitHub Desktop.
A pattern for category-limited navigation using Liquid in Jekyll. The `if` statement only generates a nav link if the URL for the next/previous post exists *and* if the category for the next post is of the same type. This pattern assumes that one is using categories to describe types of post (e.g. writing, photos, videos and so on) to build mult…
<footer class="post-nav">
{% if page.next.url and page.next.categories contains 'writing' %}
<a class="more next" href="{{page.next.url}}" title="Later article: {{page.next.title}}">Next</a>
{% endif %}
{% if page.previous.url and page.previous.categories contains 'writing' %}
<a class="more previous" href="{{page.previous.url}}" title="Earlier article: {{page.previous.title}}">Previous</a>
{% endif %}
</footer>
@Sakrecoer
Copy link

i think i found the reason for this to be unconsistent in my scenario. The loop stops if the next/previous post exists but is not in the specified category.... working on it :) i'll get back whenever i figure this out....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment