Skip to content

Instantly share code, notes, and snippets.

@a-am
Last active January 20, 2016 22:25
Show Gist options
  • Save a-am/81385d0254d25d9cea55 to your computer and use it in GitHub Desktop.
Save a-am/81385d0254d25d9cea55 to your computer and use it in GitHub Desktop.
Pagination with Venti events.ds
{% set today = now %}
{% set total = craft.venti.allEvents().startDate('and', '>= ' ~ today).total() %}
{% set limit = 5 %}
{% set prev = 1 %}
{% set next = 2 %}
{% set pge = craft.request.getParam('pg') ? craft.request.getParam('pg') : 0 %}
{% set lastPage = "" %}
{% set offset = (pge - 1) * limit %}
{% if total % limit == 0 %}
{% set lastPage = (total // limit) %}
{% else %}
{% set lastPage = (total // limit) + 1 %}
{% endif %}
{% if pge - 1 <= 0 %}
{% set prev = 0 %}
{% set next = 2 %}
{% elseif pge == lastPage %}
{% set prev = pge - 1 %}
{% set next = lastPage %}
{% else %}
{% set prev = pge - 1 %}
{% set next = pge + 1 %}
{% endif %}
{% set events = craft.venti.allEvents().startDate('and', '>= ' ~ today).limit(limit).offset(offset).find() %}
{# Now use events in for loop to create list #}
{# Pagination buttons to get previous and next page #}
<a href="?pg={{ prev }}">Previous</a>
{% for item in 1.. lastPage|abs %}
<a href="?pg={{ loop.index }}">{{ loop.index }}</a>
{% endfor %}
<a href="?pg={{ next }}">Next</a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment