File: /var/www/hcv/wp-content/themes/hockey/templates/partials/pagination.twig
{% if posts.pagination.pages is not empty %}
<div class="pagination">
{% if posts.pagination.pages|first and posts.pagination.prev != '' %}
<a href="{{ posts.pagination.pages|first.link }}" class="previous">FIRST</a>
{% else %}
<span class="previous disabled">FIRST</span>
{% endif %}
{% set current = posts.pagination.current %}
{% set total = posts.pagination.total %}
{# if current page is less than 3 show first 5 pages #}
{% if current <= 3 %}
{% for page in posts.pagination.pages %}
{% if page.title <= 5 %}
{% if page.link %}
<a href="{{page.link}}" class="page">{{page.title}}</a>
{% else %}
<span class="page active">{{page.title}}</span>
{% endif %}
{% endif %}
{% endfor %}
{# if current page is in last 3 show last 5 pages #}
{% elseif current >= (total - 2) %}
{% for page in posts.pagination.pages %}
{% if page.title >= (total - 4) %}
{% if page.link %}
<a href="{{page.link}}" class="page">{{page.title}}</a>
{% else %}
<span class="page active">{{page.title}}</span>
{% endif %}
{% endif %}
{% endfor %}
{# else show two pages before and two after the current page #}
{% else %}
{% for page in posts.pagination.pages %}
{% if (page.title >= (current - 2)) and (page.title <= ( current + 2 ))%}
{% if page.link %}
<a href="{{page.link}}" class="page">{{page.title}}</a>
{% else %}
<span class="page active">{{page.title}}</span>
{% endif %}
{% endif %}
{% endfor %}
{% endif %}
{% if posts.pagination.pages|last and posts.pagination.next != '' %}
<a href="{{ posts.pagination.pages|last.link }}" class="next">LAST</a>
{% else %}
<span class="next disabled">LAST</span>
{% endif %}
</div>
{% endif %}
{# {% if posts.pagination.pages is not empty %}
<div class="pagination">
{% if posts.pagination.pages|first and posts.pagination.prev != '' %}
<a href="{{ posts.pagination.pages|first.link }}" class="previous">FIRST</a>
{% else %}
<span class="previous disabled">FIRST</span>
{% endif %}
{% for page in posts.pagination.pages %}
{% if page.link %}
<a href="{{page.link}}" class="page">{{page.title}}</a>
{% else %}
<span class="page active">{{page.title}}</span>
{% endif %}
{% endfor %}
{% if posts.pagination.pages|last and posts.pagination.next != '' %}
<a href="{{ posts.pagination.pages|last.link }}" class="next">LAST</a>
{% else %}
<span class="next disabled">LAST</span>
{% endif %}
</div>
{% endif %} #}