Get last article - Shopify / Liquid

Viewed 863

I'm trying to retrieve the most recent article on a blog. My current code below does not output anything.

{% for article in blogs['myblog'].articles.last %}
  {{ article.title }}
{% endfor %}
2 Answers

It can be done like this using forloop.last:

{% for article in blogs['myblog'].articles %}
    {% if forloop.last == true %}
         {{ article.title }}
    {% endif %}
{% endfor %}

This assumes that blogs is a variable. Otherwise, try replacing blogs['myblog'].articles with blog.articles.

Related