Liquid Iterate Through All Articles in All Blogs

Highlighted
New Member
5 0 0
Is it possible to iterate through all articles posted to a site? So, if I have Blog A and Blog B, each with 5 articles, can I iterate through the ten total articles that have been published on all my blogs?
0 Likes
Highlighted
Shopify Partner
165 34 59

Yes it is possible. You need to loop through all the blogs first and then loop through articles from each blog. 

Problem Solved? ✔️Accept the solution so you can help others.
* Email: fayyazraza@gmail.com * Skype: fayyaz_raza
0 Likes
Highlighted
Shopify Partner
165 34 59
{% for blog in blogs %}
  {% for article in blog.articles %}
    {{ article.title }}
  {% endfor %} 
{% endfor %}
Problem Solved? ✔️Accept the solution so you can help others.
* Email: fayyazraza@gmail.com * Skype: fayyaz_raza
2 Likes
Shopify Partner
165 34 59

There is another way also 

If you don't mind creating a special link list, with links that point to all blogs, you could go like this:

{% for link in linklists.blogs.links %}
  {% assign blog = link.object %}
  {% for article in blog.articles %}
    {{ article.title }}
  {% endfor %} 
{% endfor %}
Problem Solved? ✔️Accept the solution so you can help others.
* Email: fayyazraza@gmail.com * Skype: fayyaz_raza
2 Likes
Highlighted
New Member
5 0 0
This is very close to the solution. I've added all the blog articles to one link list, and can iterate through each. Using your first solution and iterating through one blog at a time leaves the posts ordered by blog/date instead of only by date, which doesn't work for this purpose. The issue now is that Shopify does not allow you to paginate through a linklist. That is the ultimate behavior I'm looking for: iterate through all articles, display all articles on a single page, and add pagination to that page so that only X number of articles appear per page. It's a shame there is no global 'articles' variable in liquid! This would've been so easy! Thank you for your help Fayyaz
0 Likes
Highlighted
Shopify Partner
165 34 59

Please like and accept the solutions. I would highly appreciate that. Thanks

Problem Solved? ✔️Accept the solution so you can help others.
* Email: fayyazraza@gmail.com * Skype: fayyaz_raza
0 Likes
Highlighted
Tourist
9 0 0

Hi Fayyaz, I'm trying to use this solution on a page template I've made - but it doesn't show anything - seems like the "blogs" object is empty?

I also tried the linklists method and that didn't work either. Does this only work on the blog.liquid templates? Because I'm trying to do it on a pages template.

 

Thanks in advance!

0 Likes
Highlighted
Shopify Partner
165 34 59

It works any where. You need replace your linklist handle with blogs Thanks

Problem Solved? ✔️Accept the solution so you can help others.
* Email: fayyazraza@gmail.com * Skype: fayyaz_raza
0 Likes
Highlighted
Shopify Partner
165 34 59
{% for link in linklists.yourlinklisthandle.links %}
  {% assign blog = link.object %}
  {% for article in blog.articles %}
    {{ article.title }}
  {% endfor %} 
{% endfor %}
Problem Solved? ✔️Accept the solution so you can help others.
* Email: fayyazraza@gmail.com * Skype: fayyaz_raza
0 Likes
Highlighted
Tourist
9 0 0

Hm, so I'm confused about that part - how and where are you actually declaring this linklist?

Am I completely getting the concept of linklists wrong?

0 Likes