Skip to content

Instantly share code, notes, and snippets.

@juddlyon
Created August 15, 2019 19:22
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 juddlyon/5f4d63b9fe30f459aa2d78d73119d94c to your computer and use it in GitHub Desktop.
Save juddlyon/5f4d63b9fe30f459aa2d78d73119d94c to your computer and use it in GitHub Desktop.
Craft 3 Pagination with Bootstrap 4
{# - https://getbootstrap.com/docs/4.0/components/pagination/ -#}
{# - https://docs.craftcms.com/v3/dev/tags/paginate.html -#}
{%- set query = craft.entries.section('yourSectionHandle').limit(10) -%}
{%- paginate query as pageInfo, pageEntries -%}
<ol>
{%- for entry in pageEntries -%}
<li><a href="{{ entry.url }}">{{ entry.title }}</a></li>
{%- endfor -%}
</ol>
<nav aria-label="Pagination">
<ul class="pagination">
{%- if pageInfo.prevUrl -%}
<li class="page-item">
<a class="page-link" href="{{ pageInfo.prevUrl }}" aria-label="Previous">
<span aria-hidden="true">&laquo;</span>
<span class="sr-only">Previous</span>
</a>
</li>
{%- endif -%}
{%- for page, url in pageInfo.getPrevUrls(10) -%}
<li class="page-item">
<a class="page-link" href="{{ url }}">
{{ page }}
</a>
</li>
{%- endfor -%}
{%- if pageInfo.currentPage -%}
<li class="page-item active">
<a class="page-link" href="#">
{{ pageInfo.currentPage }}
<span class="sr-only">(current)</span>
</a>
</li>
{%- endif -%}
{%- for page, url in pageInfo.getNextUrls(10) -%}
<li class="page-item">
<a class="page-link" href="{{ url }}">
{{ page }}
</a>
</li>
{%- endfor -%}
{%- if pageInfo.nextUrl -%}
<li class="page-item">
<a class="page-link" href="{{ pageInfo.nextUrl }}" aria-label="Next">
<span aria-hidden="true">&raquo;</span>
<span class="sr-only">Next</span>
</a>
</li>
{% endif %}
</ul>
</nav>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment