Created
January 18, 2016 14:11
-
-
Save freakdesign/5682e28a881902d1fcab to your computer and use it in GitHub Desktop.
Show recent articles from all Blogs in Shopify
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% 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 %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the code snippet!
Any way to have it support paging?