Reputation: 9587
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.
Upvotes: 0
Views: 248
Reputation: 3111
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:
<div>
{% 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> » <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 %}
</div>
Upvotes: 1