Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save lukeburford/6550248 to your computer and use it in GitHub Desktop.
Save lukeburford/6550248 to your computer and use it in GitHub Desktop.
Display random post from a Shopify blog, for example on the store homepage. Shopify caches it's pages so a homepage refresh will not show a new post, but adding an item to the cart and returning to the homepage will. Based on: http://wiki.shopify.com/Featuring_one_randomly_picked_product
{% capture index %}{{ 'now' | date: '%S' | times: collections.frontpage.products.size | divided_by: 60 }}{% endcapture %}
{% for article in blogs.blog-name.articles offset:index limit:1 %}
<a href="{{article.url}}">{{ article.title }}</a>
{% endfor %}
@Calzzetta
Copy link

Thank you for sharing! Why total of products instead of total of posts?

{% capture index %}{{ 'now' | date: '%S' | times: blogs.blog-name.articles.size | divided_by: 60 }}{% endcapture %}

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