This pagination liquid code is an extract of the public repository from http://nicolas-hoizey.com/, where you can see it in action.
Last active
October 27, 2015 19:00
-
-
Save nhoizey/468157e38bc8bbe1e6a5 to your computer and use it in GitHub Desktop.
Jekyll pagination
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
{% if paginator.total_pages > 1 %} | |
<ul class="pagination"> | |
{% if paginator.previous_page %} | |
{% if paginator.previous_page == 1 %} | |
<li><a href="/">«</a></li> | |
{% else %} | |
<li><a href="/{{paginator.previous_page}}">«</a></li> | |
{% endif %} | |
{% else %} | |
<li class="disabled">«</li> | |
{% endif %} | |
{% if paginator.page == 1 %} | |
<li><strong>1</strong></li> | |
{% else %} | |
<li><a href="/">1</a></li> | |
{% endif %} | |
{% assign page_start = 2 %} | |
{% if paginator.page > 5 %} | |
{% assign page_start = paginator.page | minus: 2 %} | |
<li class="disabled">…</li> | |
{% endif %} | |
{% assign page_end = paginator.total_pages | minus: 1 %} | |
{% assign to_end = paginator.total_pages | minus: paginator.page %} | |
{% if to_end > 4 %} | |
{% assign page_end = paginator.page | plus: 2 %} | |
{% endif %} | |
{% for index in (page_start..page_end) %} | |
{% if index == paginator.page %} | |
<li><strong>{{index}}</strong></li> | |
{% else %} | |
<li><a href="/{{index}}">{{index}}</a></li> | |
{% endif %} | |
{% endfor %} | |
{% if to_end > 4 %} | |
<li class="disabled">…</li> | |
{% endif %} | |
{% if paginator.page == paginator.total_pages %} | |
<li><strong>{{paginator.page}}</strong></li> | |
{% else %} | |
<li><a href="/{{paginator.total_pages}}">{{paginator.total_pages}}</a></li> | |
{% endif %} | |
{% if paginator.next_page %} | |
<li><a href="/{{paginator.next_page}}">»</a></li> | |
{% else %} | |
<li class="disabled">»</li> | |
{% endif %} | |
</ul> | |
{% endif %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment