Skip to content

Instantly share code, notes, and snippets.

@freakdesign
Created January 18, 2016 14:11
Show Gist options
  • Save freakdesign/5682e28a881902d1fcab to your computer and use it in GitHub Desktop.
Save freakdesign/5682e28a881902d1fcab to your computer and use it in GitHub Desktop.
Show recent articles from all Blogs in Shopify
{% comment %}
Code by Jason @ Freakdesign for this blog post:
http://freakdesign.com.au/blogs/news/105090695-show-the-latest-shopify-articles-from-all-blogs
---
First add all the handles of the blogs you want to include.
In this example I just use my own two blogs - works and news.
{% endcomment %}
{% assign featuredBlogs = 'works,news' | split:',' %}
{% comment %}
Set the featuredArticles variable to false by default.
{% endcomment %}
{% assign featuredArticles = false %}
{% comment %}
Grab the last 50 (default) articles from each Blog. Add the articles to the featureArticles variable.
{% endcomment %}
{% for featuredBlog in featuredBlogs %}
{% if blogs[featuredBlog].articles %}
{% if featuredArticles %}
{% assign featuredArticles = featuredArticles | concat:blogs[featuredBlog].articles %}
{% else %}
{% assign featuredArticles = blogs[featuredBlog].articles %}
{% endif %}
{% endif %}
{% endfor %}
{% comment %}
If featuredArticles is not false we should have articles to show - so let's do it!
{% endcomment %}
{% if featuredArticles %}
{% assign featuredArticles = featuredArticles | sort:'published_at' | reverse %}
{% comment %}
Now a quick example of showing the latest 10 articles from our master article list
{% endcomment %}
{% for article in featuredArticles limit:10 %}
<p><b>{{ article.title }}: </b><br>{{ article.published_at }}</p>
{% endfor %}
{% endif %}
@dshaw002
Copy link

dshaw002 commented Oct 2, 2017

Thanks for the code snippet!

Any way to have it support paging?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment