Forked from budparr/jekyll-collections-prev-next.html
Last active
May 16, 2019 15:46
-
-
Save johnfmorton/6c395361d259b23409ee6559fd909d5c to your computer and use it in GitHub Desktop.
Previous Next Links for Jekyll Collections - with wrap around to beginning link and last link when needed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% capture the_collection %}{{page.collection}}{% endcapture %} | |
{% if page.collection %} | |
{% assign document = site[the_collection] %} | |
{% endif %} | |
<h1>TITLE: {{ page.title }}</h1> | |
{% for links in document %} | |
{% if forloop.first %} | |
{% assign first = links %} | |
{% endif %} | |
{% if forloop.last %} | |
{% assign last = links %} | |
{% endif %} | |
{% if links.title == page.title %} | |
{% unless forloop.first %} | |
{% assign prevurl = prev.url %} | |
{% endunless %} | |
{% unless forloop.last %} | |
{% assign next = document[forloop.index] %} | |
{% assign nexturl = next.url %} | |
{% endunless %} | |
{% endif %} | |
{% assign prev = links %} | |
{% endfor %} | |
{% assign firsturl = first.url %} | |
{% assign lasturl = last.url %} | |
{% if prevurl %}<a href="{{prevurl}}" class="prev">Prev</a>{% else %}<a href="{{lasturl}}" class="prev">Prev</a>{% endif %}<br /> | |
{% if nexturl %}<a href="{{nexturl}}" class="nxt">Next</a>{% else %}<a href="{{firsturl}}" class="prev">Next</a>{% endif %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment