Created
December 21, 2018 13:08
-
-
Save StyxOfDynamite/bcd8c20f3f700e53f355851b3821a980 to your computer and use it in GitHub Desktop.
pagination - twig
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
<!-- page 1 --> | |
{% if posts.currentPage == 1 %} | |
{% for page in posts.currentPage .. posts.currentPage + 3 %} | |
<li class="{{ posts.currentPage == page ? 'active' : null }}"> | |
<a href="{{ this.page.baseFileName|page({ (pageParam): page }) }}">{{ page }}</a> | |
</li> | |
{% endfor %} | |
{% endif %} | |
<!-- page 2 --> | |
{% if posts.currentPage == 2 %} | |
{% for page in posts.currentPage -1 .. posts.currentPage + 3 %} | |
<li class="{{ posts.currentPage == page ? 'active' : null }}"> | |
<a href="{{ this.page.baseFileName|page({ (pageParam): page }) }}">{{ page }}</a> | |
</li> | |
{% endfor %} | |
{% endif %} | |
<!-- page 3 --> | |
{% if posts.currentPage == 3 %} | |
{% for page in posts.currentPage -2 .. posts.currentPage + 3 %} | |
<li class="{{ posts.currentPage == page ? 'active' : null }}"> | |
<a href="{{ this.page.baseFileName|page({ (pageParam): page }) }}">{{ page }}</a> | |
</li> | |
{% endfor %} | |
{% endif %} | |
<!-- Handle loop for main pagination --> | |
{% if posts.currentPage > 3 and posts.currentPage <= posts.lastPage - 3 %} | |
{% for page in posts.currentPage - 3 .. posts.currentPage + 3 %} | |
<li class="{{ posts.currentPage == page ? 'active' : null }}"> | |
<a href="{{ this.page.baseFileName|page({ (pageParam): page }) }}">{{ page }}</a> | |
</li> | |
{% endfor %} | |
{% endif %} | |
<!-- page last - 2, page last -1, page last --> | |
{% if posts.currentPage >= posts.lastPage - 2 and posts.currentPage <= posts.lastPage%} | |
{% for page in posts.currentPage - 3 .. posts.lastPage %} | |
<li class="{{ posts.currentPage == page ? 'active' : null }}"> | |
<a href="{{ this.page.baseFileName|page({ (pageParam): page }) }}">{{ page }}</a> | |
</li> | |
{% endfor %} | |
{% endif %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment