So heres a recent posts query with the last 5 posts.
{% for post in site.posts limit:5 %}
<li>
< a href="{{ post.url }}">{{ post.title }}</a>
</li>
{% endfor %}
However, this shows the current one too, if its one of the 5 latest posts. I tried to include an if statement which check for the URL, but how can I add +1 to the limit variable?
P.S.: I included a space in the anchor tag so its readable as code
Checking the url should work. Just loop over six items and hide the last one when you do not find a match.
{% for post in site.posts limit:6 %}
{% if post.url != page.url %}
{% if forloop.index < 6 or found %}
<li>
<a href="{{ post.url }}">{{ post.title }}</a>
</li>
{% endif %}
{% else %}
{% assign found = true %}
{% endif %}
{% endfor %}
What the code does (step by step):
*allowing you to loop/iterate over post number 6
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With