Exclude current entry from recent requests in Jekyll?

So, you have the last question with the latest posts.

 {% for post in site.posts limit:5 %}
     <li>
    < a href="{{ post.url }}">{{ post.title }}</a>
     </li>
   {% endfor %}

However, this also shows the current one, if this is one of the last 5 messages. I tried to include an if statement that checks the URL, but how can I add +1 to the limit variable?

PS: I included a space in the anchor tag so that it can be read as code

+4
source share
1 answer

URL validation should work. Just drag and drop the six elements and hide the last when you don't 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):

  • cycle over 6 posts
  • check if the post is NOT the current page / message
  • / 1 5 *
  • , /

*, / 6

+5

Source: https://habr.com/ru/post/1659952/


All Articles