Liquid, JavaScript, themes, sales channels
(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.
{% 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?
Solved! Go to the solution
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.
BUMP
You can't mess with the pagination/sort of blog posts with liquid. You can do some hacky things with javascript though.
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.
Awesome! Thanks, I’ll dig into that and see what I can find.
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?
Portrait of Stephen positioned next to an image of planet Earth, with the Stephen's World ...
By JasonH Mar 18, 2024Digital marketers and app developers have tracked activity in apps and websites for yea...
By Ollie Mar 13, 2024February was an exciting month with Shopify Editions, informative webinars, and more! F...
By JasonH Mar 7, 2024