paging.twig.example 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. {# This needs 3 variables to be set:
  2. count - how many results to display altogether
  3. paging_array - array of result pages
  4. paging_url_base - the base URL for pagination links
  5. #}
  6. {% if config.tagblog.paging.items > 0 and count > config.tagblog.paging.items %}
  7. {% set p = url_param('p','int',1) %}
  8. {% set paging_url_base = paging_url_base ~ 'p=' %}
  9. {% set offset = (p - 1) * config.tagblog.paging.items %}
  10. {% set lastpage = count//config.tagblog.paging.items %}
  11. {% if count%config.tagblog.paging.items > 0 %}{% set lastpage = lastpage + 1 %}{% endif %}
  12. {% if config.tagblog.paging.top %}
  13. {% block pagination %}
  14. <div class="pagination clearfix">
  15. {% if offset >= config.tagblog.paging.items %}
  16. <div class="previous"><span class="first"><a href="{{paging_url_base}}1">&lt;&lt;First</a></span>{% if p > 2 %}<span><a href="{{paging_url_base}}{{p-1}}">&lt;Previous</a></span>{% endif %}</div>
  17. {% endif %}
  18. <div class="current">- {{ p }}/{{ lastpage }} -</div>
  19. {% if offset + config.tagblog.paging.items < count %}
  20. <div class="next">{% if p +1 < lastpage %}<span><a href="{{paging_url_base}}{{p+1}}">Next&gt;</a></span>{% endif %}<span class="last"><a href="{{paging_url_base}}{{lastpage}}">Last>></a></span></div>
  21. {% endif %}
  22. </div>
  23. {% endblock %}
  24. {% endif %}
  25. {% for page in paging_array|slice(offset,config.tagblog.paging.items) %}
  26. {% include 'includes/postlistitem.twig' %}
  27. {% endfor %}
  28. {% if config.tagblog.paging.bottom %}
  29. {{ block('pagination') }}{# same as above #}
  30. {% endif %}
  31. {% else %}
  32. {# if pagination is disabled - just list all pages #}
  33. {% for page in paging_array %}
  34. {% include 'includes/postlistitem.twig' %}
  35. {% endfor %}
  36. {% endif %}