-
-
Save ahmedtalaltwd7/b9620adee5fec0a6c1f87dd697f063ea 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
<!-- | |
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: '//', '/' }}">« Prev</a> | |
{% else %} | |
<span>« 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 »</a> | |
{% else %} | |
<span>Next »</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