Last active
October 20, 2021 10:24
-
-
Save shopifypartners/ab0eb8a26fb97880b4ac97b60e790e00 to your computer and use it in GitHub Desktop.
Accessible pagination with Liquid - https://www.shopify.com/partners/blog/shopify-pagination
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{%- paginate blog.articles by 5 -%} | |
{%- for article in blog.articles -%} | |
<!-- show blog article details here --> | |
{%- endfor -%} | |
{%- if paginate.pages > 1 -%} | |
<nav role="navigation"> | |
<ol class="pagination"> | |
{%- if paginate.previous-%} | |
<li> | |
<a href="{{ paginate.previous.url }}"> | |
<span aria-hidden="true">«</span> | |
Previous <span class="visuallyhidden">page</span> | |
</a> | |
</li> | |
{%- else -%} | |
<li class="disabled"> | |
<span aria-hidden="true">«</span> | |
Previous <span class="visuallyhidden">page</span> | |
</li> | |
{%- endif -%} | |
{%- for part in paginate.parts -%} | |
{%- if part.is_link -%} | |
<li> | |
<a href="{{ part.url }}"> | |
<span class="visuallyhidden">page</span> {{ part.title }} | |
</a> | |
</li> | |
{%- else -%} | |
{%- if part.title == paginate.current_page -%} | |
<li class="active" aria-current="page"> | |
<span class="visuallyhidden">page</span> {{ part.title }} | |
</li> | |
{%- else -%} | |
<li> | |
<span class="visuallyhidden">page</span> {{ part.title }} | |
</li> | |
{%- endif -%} | |
{%- endif -%} | |
{%- endfor -%} | |
{%- if paginate.next -%} | |
<li> | |
<a href="{{ paginate.next.url }}"> | |
Next <span class="visuallyhidden">page</span> | |
<span aria-hidden="true">»</span> | |
</a> | |
</li> | |
{%- else -%} | |
<li class="disabled"> | |
Next <span class="visuallyhidden">page</span> | |
<span aria-hidden="true">»</span> | |
</li> | |
{%- endif -%} | |
</ol> | |
</nav> | |
{%- endif -%} | |
{%- endpaginate -%} | |
<style> | |
.visuallyhidden { | |
border: 0; | |
clip: rect(0 0 0 0); | |
height: 1px; | |
margin: -1px; | |
overflow: hidden; | |
padding: 0; | |
position: absolute; | |
width: 1px; | |
white-space: nowrap; | |
} | |
.pagination li { | |
display: inline; | |
margin: 0 5px; | |
} | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment