Skip to content

Instantly share code, notes, and snippets.

@StyxOfDynamite
Created December 21, 2018 13:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save StyxOfDynamite/bcd8c20f3f700e53f355851b3821a980 to your computer and use it in GitHub Desktop.
Save StyxOfDynamite/bcd8c20f3f700e53f355851b3821a980 to your computer and use it in GitHub Desktop.
pagination - twig
<!-- 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