1

I establish my Blog with the help of jekyll bootstrap and deploy it on github. Here is my question:
I want to add a sidebar which lists my newest 10 posts. When I use the code below, it lists all my posts:

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

BUT, I only want to list the newest 10 posts(if the num of all posts less than 10, list all),how can I do?
Thank You for your answer!

hazir
  • 55
  • 1
  • 4

1 Answers1

4

I don't have the environment to test it, but you might want to try limit keyword, see documentation here. I assume it will show all if limit is not reached.

<ul>
   {% for post in site.posts limit:10 %}
       <li><a href="{{ BASE_PATH }}{{ post.url }}">{{ post.title }}</a></li>
   {% endfor %}
</ul>
Yi Zeng
  • 32,020
  • 13
  • 97
  • 125