Skip to content

Instantly share code, notes, and snippets.

@kylekeesling
Created October 31, 2013 12:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kylekeesling/7248951 to your computer and use it in GitHub Desktop.
Save kylekeesling/7248951 to your computer and use it in GitHub Desktop.
Simple Jekyll Paginator Logic I didn't like the pagination logic provided in the Jekyll Docs (http://jekyllrb.com/docs/pagination/) since it repeated the HTML for displaying the button, so I came up w/ this. It stores the proper previous page path into a liquid variable then plops it into the HREF so you only have to code your button once
{% if paginator.previous_page %}
{% if paginator.previous_page == 1 %}
{% capture previous_page %}/{% endcapture %}
{% else %}
{% capture previous_page %}/page{{ paginator.previous_page }}{% endcapture %}
{% endif %}
<a href="{{ previous_page }}" class="previous">&larr; Newer Posts</a>
{% endif %}
{% if paginator.next_page %}
<a href="/page{{ paginator.next_page }}" class="next">Older Posts &rarr;</a>
{% endif %}
@NetOpWibby
Copy link

SO much better.

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