Creating an Accessible Pagination with Liquid

Shopify pagination

One of the key elements when building an online store is to create a pagination system. Pagination enables users to navigate through a series of pages in which content has been split up for design purposes, usability, faster loading, and so on. Pagination might not be the sexiest component of an online store, but it’s definitely one of the most important ones.

Grow your business with the Shopify Partner Program

Whether you offer marketing, customization, or web design and development services, the Shopify Partner Program will set you up for success. Join for free and access revenue share opportunities, tools to grow your business, and a passionate commerce community.

Sign up

What is pagination, and what can I paginate in a theme?

Pagination is an ordered numbering of pages, usually located at the top or bottom of a webpage. Pagination helps to split products, blog articles, and search results across multiple pages. Within Shopify it is a necessary part of theme design, as you are limited to 50 results per page in anyforloop.

In its simplest form thepaginatetag works with thefortag to split content into multiple web pages. It must wrap afortag block that loops through an array.

{% paginate collection.products by 5 %} {% for product in collection.products %} {% endfor %} {% endpaginate %}

You might also like:Understanding hreflang Tags for Multilingual Stores.

Building an accessible pagination

My favorite tutorials show a full example of the outcome immediately, to save time and give context. For this article I think it’s best to see the full example upfront and walk you through the code and what makes this pagination accessible. How each of the elements of this example work together to create a functioning accessible pagination is explained below, so read on to understand how this was built. Here’s the full example:

View on GitHub

Paginate tags

佛r this code to work, it must appear withinpaginatetags. Within thepaginatetags, you can access thepaginateobjectand create markup for your pagination to render properly.

In this example we’re paginating blog articles, so this code would appear on theblog.liquidtemplate, or in a section template that was being included in theblog.liquidtemplate.

You can set a “limit” or number of blog posts to show on one page with your pagination by specifying thebyparameter. This parameter is followed by an integer between 1 and 50 that tells thepaginate它应该输出每个页面标签多少结果。佛r example, if I wanted to show 10 articles per page with my pagination, then I would change the example above to read:

{%- paginate blog.articles by 10 -%}

Using semantic markup

In the full example, you’ll notice that we’ve used anavelement and an

    element. The
Topics:

Grow your business with the Shopify Partner Program

Learn more