Reputation: 144
I want to get the last 3 posts by category on a page, except for the current page in this filter.
My code is not working:
{% for cat in page.categories[0] %}
{% for post in site.categories[cat] limit: 3 %}
{% if post.title == page.title %}
{% break %}
{% endif %}
<div class="item">
<a href="{{ post.url | relative_url }}">
<div class="image" style="background-image: url({{ post.image }});"></div>
<div class="item-text main">
<h1>{{ post.title }}</h1>
</div>
</a>
</div>
{% endfor %}
{% endfor %}
Upvotes: 0
Views: 226
Reputation: 138
You can replace
{% if post.title == page.title %}
{% break %}
{% endif %}
with
{% unless post.url == page.url %}
Full Code
{% for cat in page.categories[0] %}
{% for post in site.categories[cat] limit: 3 %}
{% unless post.url == page.url %}
<div class="item">
<a href="{{ post.url | relative_url }}">
<div class="image" style="background-image: url({{ post.image }});">
</div>
<div class="item-text main">
<h1>{{ post.title }}</h1>
</div>
</a>
</div>
{% endunless %}
{% endfor %}
{% endfor %}
Upvotes: 1