Solved

What's the solution for pagination error in Shopify blog posts sorting?

jao
Excursionist
17 0 3

(asking again because I didn't get any replies on my previous 2 posts and Shopify support staff refuses to provide support)


I'm trying to create a paginated list with blog articles that are sorted by time of update.

But it results in this error:

Liquid error (sections/blog-template.liquid line 72): Array 'blog_posts_sorted' is not paginateable.

This is the relevant liquid code:

 

{% assign blog_posts_sorted = blog.articles | sort: "updated_at" %}

{%- paginate blog_posts_sorted by articles_per_page -%}

How do I paginate a sorted list of blog articles?

Accepted Solution (1)
gina-gregory
Shopify Expert
742 51 211

This is an accepted solution.

Generally speaking, you can gather all your posts into a JSON array by fetching the results of each paginated page, then sort that by the updated_at field. Then output the articles and add a javascript-based pagination system. If you have a ton of posts, this could get slow, but you can try to cache the results in localStorage or something so only the first load is slow.

View solution in original post

Replies 6 (6)

jao
Excursionist
17 0 3

BUMP

gina-gregory
Shopify Expert
742 51 211

You can't mess with the pagination/sort of blog posts with liquid. You can do some hacky things with javascript though.

jao
Excursionist
17 0 3
Thanks, that is good to know. Do you perhaps have any links to the docs that would guide me in the general direction?
gina-gregory
Shopify Expert
742 51 211

This is an accepted solution.

Generally speaking, you can gather all your posts into a JSON array by fetching the results of each paginated page, then sort that by the updated_at field. Then output the articles and add a javascript-based pagination system. If you have a ton of posts, this could get slow, but you can try to cache the results in localStorage or something so only the first load is slow.

jao
Excursionist
17 0 3

Awesome! Thanks, I’ll dig into that and see what I can find.

shopdev4711
Visitor
1 0 0

Could you please get into more detail? I tried the same as Jao and did not succeed. My goal is to create a dictionary with blog articles. Currently 80 articles so far, but slowly expanding. Currently I only get 50 "random" articles, when fetching {% assign sorted_articles = blog.articles | sort: 'title' %}

My goal is to display the first 50 articles on one page, then the next 50, etc. in alphabetical order. Javascript pagination is only a viable solution if it may be crawlable by google.

I tried it with tagging, so that the search crawler at least gets all of the articles and not only a subset, which seems to be random or maybe based on update-date?