Skip to content

Instantly share code, notes, and snippets.

@sharu725
Last active December 2, 2021 00:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sharu725/3c3a3971955d02e24f45edc864bf8172 to your computer and use it in GitHub Desktop.
Save sharu725/3c3a3971955d02e24f45edc864bf8172 to your computer and use it in GitHub Desktop.
Jekyll Pagination
<!--
Before implementing this Jekyll snippet make sure
1. "plugins: jekyll-paginate" is added in the _config.yml file.
2. for loop has "paginator.post" instead of "site.posts".
-->
{% if paginator.total_pages > 1 %}
<div class="wj-pagination">
{% if paginator.previous_page %}
<a href="{{ paginator.previous_page_path | prepend: site.baseurl | replace: '//', '/' }}">&laquo; Prev</a>
{% else %}
<span>&laquo; Prev</span>
{% endif %}
{% for page in (1..paginator.total_pages) %}
{% if page == paginator.page %}
<span class="active">{{ page }}</span>
{% elsif page == 1 %}
<a href="/">{{ page }}</a>
{% else %}
<a href="{{ site.paginate_path | prepend: site.baseurl | replace: '//', '/' | replace: ':num', page }}">{{ page }}</a>
{% endif %}
{% endfor %}
{% if paginator.next_page %}
<a href="{{ paginator.next_page_path | prepend: site.baseurl | replace: '//', '/' }}">Next &raquo;</a>
{% else %}
<span>Next &raquo;</span>
{% endif %}
</div>
{% endif %}
<style>
.wj-pagination {
text-align: center;
}
.wj-pagination a, .wj-pagination span {
padding: 7px 18px;
border: 1px solid #eee;
margin-left: -2px;
margin-right: -2px;
background-color: #ffffff;
display: inline-block;
}
.wj-pagination a:hover {
background-color: #f1f1f1;
color: #333;
}
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment