Reputation: 2223
How can I loop through all pages in Shopify? I have tried this:
{% for page in pages %}
{{ page.title }} <br>
{% endfor %}
It doesn't work.
Upvotes: 0
Views: 1984
Reputation: 2167
You can iterate through up to 50 pages at a time with Liquid pagination:
<ul>
{%- paginate pages by 50 -%}
{%- for p in pages -%}
<li>{{ p.title }}</li>
{%- endfor -%}
{{ paginate | default_pagination: next: 'Older', previous: 'Newer' }}
{%- endpaginate -%}
</ul>
https://shopify.dev/docs/themes/liquid/reference/objects#pages
Upvotes: 1
Reputation: 2223
Apparently it is not possible to iterate over pages in liquid, but we can do it with JS:
$.getJSON('/pages.json', function(data) {
for(p in data.pages ){
console.log( data.pages[ p ].title );
}
});
Upvotes: 0