picocms / Pico

Pico is a stupidly simple, blazing fast, flat file CMS.
http://picocms.org/
MIT License
3.82k stars 616 forks source link

Latest posts at the start page #485

Closed CodeTipsy closed 5 years ago

CodeTipsy commented 5 years ago

Hello, for all posts: `{% for page in pages|sort_by("time")|reverse %} {% if page.id starts with "blog/" and not page.hidden %}

{{ page.title }}

{{ page.date_formatted }}

{{ page.description }}

{% endif %}

{% endfor %}`

And for last post at the start page? Can you please tell me?

Regards

PhrozenByte commented 5 years ago

Try {% set latest_page = pages|sort_by("time")|last %} (it's the same as pages|sort_by("time")|reverse|first, but skips the reverse filter, so that the latest post is actually the last item in the sorted pages list)

CodeTipsy commented 5 years ago

`{% for page in pages|sort_by("time")|last %} {% if page.id starts with "blog/" and not page.hidden %} {{ page.title }}

{{ page.date_formatted }}

                {% endif %}
            {% endfor %}`

Thank you very much for the information.

PhrozenByte commented 5 years ago

Sorry, I'm not sure what the exact question is. After setting the latest page's data to the latest_page variable, you can access it as usual:

{% set latest_page = pages|sort_by("time")|last %}
<a href="{{ latest_page.url }}">{{ latest_page.title }}</a> <p>{{ latest_page.date_formatted }}</p>
CodeTipsy commented 5 years ago

{% for page in pages|sort_by("time")|last %} {% if page.id starts with "blog/" and not page.hidden %} <a href="{{ page.url }}">{{ page.title }}</a> <p>{{ page.date_formatted }}</p> {% endif %} {% endfor %}

This code is perfect for my website! I just wanted to say thank you for the fantastic service.

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in two days if no further activity occurs. Thank you for your contributions! :+1: