Skip to content

Instantly share code, notes, and snippets.

@ahmedtalaltwd7
Forked from sharu725/pagination.html
Created December 2, 2021 00:54
Show Gist options
  • Save ahmedtalaltwd7/b9620adee5fec0a6c1f87dd697f063ea to your computer and use it in GitHub Desktop.
Save ahmedtalaltwd7/b9620adee5fec0a6c1f87dd697f063ea 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