Bootstrap Pagination Documentation

Use this partial template to display pagination for a collection using the recommended bootstrap 5 pagination markup.

Check our the Pagination Demo for full working examples.


Return a 404 response code for empty collections

If you are attempting to load content past page 1 and there are no results, the pagination template will automatically set the response code to 404 - No results. You can disable this behavior by setting the disable_404_for_empty_collections variable to false.


Change the size

Change the size of the pagination links using the pagination_size variable. Valid values are sm (for small) and lg (for large).

Small links

Show Full

Large links

Show Full


Change the alignment

Change the horizontal positioning of the pagination links using the pagination_justify variable. Valid values are start (for left - reversed on RTL layouts), center, and end (for right - reversed on RTL layouts).

 

Align left (start)

Show Full

{% include "/marketpath/bs5-paginate/_pagination.liquid" pagination_justify:'start' %}
Align center

Show Full

{% include "/marketpath/bs5-paginate/_pagination.liquid" pagination_justify:'center' %}
Align right (end)

Show Full

{% include "/marketpath/bs5-paginate/_pagination.liquid" pagination_justify:'end' %}


Show and hide the beginning and ending controls

By default the first, previous, next, and last links will be displayed. If they are irrelevant (ie: because you are already on the first or last page) they will still be displayed but will be disabled and will be non-functional. To hide the first and last links, set the hide_first_and_last variable to true. To hide the previous and next links, set the hide_prev_and_next variable to true.

Hide first and last link

Show Full

Hide previous and next link

Show Full


Putting it all together

Here are a few examples of how the pagination might be used. See the pagination demo for some more working examples.

Pull latest blog posts

Show Full

{% var page_param = 'p' %}
{% blog_posts posts = limit:10 page:request.query_params[page_param] sort_by:'post_date' sort_direction:'desc' %}
{% include '/path/to/blog_feed_template.liquid' %}
{% include "/marketpath/bs5-paginate/_pagination.liquid" collection:posts %}
Search by query parameter

Show Full

{% var pageparam = '__results_start__' %}
{% var limitparam = 'limit' %}
{% var limit = request.query_params[limitparam] | default: 30 | to_int %}
{% var page = request.query_params[pageparam] | default: 1 | to_int %}
{% search collection limit:limit page:page sort_by:'post_date' sort_direction:'desc' %}
{% include '/path/to/search_results.liquid' %}
{% include "/marketpath/bs5-paginate/_pagination.liquid" page_param:pageparam max_pagination_links:100 pagination_size:'sm' %}
Self-adjusting template

Show Full

{% blog_posts posts = limit:10 page:request.query_params['page'] sort_by:'post_date' sort_direction:'desc' %}

{% include '/path/to/blog_feed_template.liquid' %}

{% if posts.total_pages > 1 %}
    {% var max_pagination_links = 1 %}
    {% var hide_prev_and_next = false %}
    {% var hide_first_and_last = true %}
    {% var pagination_size = 'lg' %}
    {% if posts.page > 1 %}
        {% if posts.total_pages > 101 %}
            {% set max_pagination_links = 99 %}
            {% set pagination_size = 'sm' %}
            {% var hide_prev_and_next = true %}
            {% var hide_first_and_last = false %}
        {% elsif posts.total_pages > 10 %}
            {% set max_pagination_links = posts.total_pages %}
            {% set pagination_size = 'sm' %}
            {% var hide_prev_and_next = true %}
        {% else %}
            {% set max_pagination_links = posts.total_pages %}
            {% set pagination_size = 'md' %}
        {% endif %}
    {% endif %}
    {% include "/marketpath/bs5-paginate/_pagination.liquid" collection:posts %}
{% endif %}