Take the 2-minute tour ×

I'm using liquid (https://github.com/tobi/liquid/) to render content in my templates. I'd like to have a "recent activity" section on my homepage that will look for the latest updates across three different content types ordered by date, with a limit of four.

Is something like this possible with liquid?

So in plain language the query would be something like.. "Choose the four latest items ordered by date from content_type_1, 2 or 3"

Thanks, Mark.

share|improve this question

1 Answer 1

By content_type, I assume you mean the category of the post. You can categorize your post by adding

category: type_1

to the YAML Front Matter of your post or putting that post in a type_1/_posts folder. Once we have this, here is a slightly tacky way of doing what you want:

  {% assign count1 = true %}
  {% assign count2 = true %}
  {% assign count3 = true %}
  {% assign count4 = true %}
  {% for post in site.posts %}
     {% if post.categories contains 'type_1' or post.categories contains 'type_2' or ... %}
        {% if count1 == true or count2 == true or count3 == true or count4 == true %}
           <li><span>{{ post.date | date_to_string }}</span> &raquo; <a href="{{ post.url }}">{{ post.title }}</a></li>
           {% if count1 == true %}
              {% assign count1 = false %}
           {% elsif count2 == true %}
              {% assign count2 = false %}
           {% elsif count3 == true %}
              {% assign count3 = false %}
           {% elsif count4 == true %}
              {% assign count4 = false %}
           {% endif %}
        {% endif %}
     {% endif %}
  {% endfor %}
share|improve this answer

Your Answer


