Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

Does GRAV track date of post update/modification?

Started by Muut Archive 10 years ago · 9 replies · 2044 views
10 years ago

I would like to display to user when the post was updated - something like modified_date. This is different from publish_date which display when the post was first published.

Does GRAV track when we last modified the post?

10 years ago

Grav does track modified_date. In fact it's the only date it really can track as that's the only date that is reliable across different OS Filesystems.

The best approach is to manually set date: in the page header. This will mean you can get this 'creation date' anytime with $page->date(). Then anytime you update the file, you can get that modified date with $page->modifiedDate().

Btw, in Twig parlance, this is page.date() and page.modifiedDate()

10 years ago

Hi,

So we could write this to have the 10 latest updated pages within the site ?

TWIG
{% for child in pages.children.nonModular.order('modifiedDate', 'desc').slice(0, 10) %}
            <div class="media-object">
                {% set showcase_image = child.media.images|first.resize(100,100).url %}
                {% if showcase_image %}
                <div class="media-object-section">
                    <img alt="{{ child.title }}" src="{{ showcase_image }}" />
                </div>
                {% endif %}

                <div class="media-object-section">
                    <h5><a href="{{ child.url }}">{% if child.menu %},{{ child.menu }},{% else %},{{ child.title }},{% endif %}</a></h5>
                </div>
            </div>
            {% endfor %}

Curent result is not the same as what is displayed on admin page for latest changed pages... What did I miss ?

👍 1
10 years ago

As alternative, trying:

TWIG
            {% set recentnews =
                page.collection({
                    'items': '@root.descendants'
                })
                .order('modifiedDate', 'desc')
                .slice(0,10)
            %}
            {% for child in recentnews %}
            <div class="media-object">
                {% set showcase_image = child.media.images|first.resize(100,100).url %}
                {% if showcase_image %}
                <div class="media-object-section">
                    <img alt="{{ child.title }}" src="{{ showcase_image }}" />
                </div>
                {% endif %}

                <div class="media-object-section"> 
                    <h5><a href="{{ child.url }}">{% if child.menu %},{{ child.menu }},{% else %},{{ child.title }},{% endif %}</a></h5>
                </div>
            </div>
            {% endfor %}

Still does not provide the expected list.

10 years ago

Hi,

It's what I did at the beginning but it was not working either. Will test it deeper, maybe rsync impacted the datetime of the files too...

10 years ago

Weird, it works now. Maybe I had some cache issues on server or browser side... Sorry for the noise

This worked:

TWIG
{% set recentnews =
                page.collection({
                    'items': '@root.descendants'
                })
                .order('modifiedDate', 'desc')
                .slice(0,10)
            %}
            {% for child in recentnews %}
            <div class="media-object">
                {% set showcase_image = child.media.images|first.resize(100,100).url %}
                {% if showcase_image %}
                <div class="media-object-section">
                    <img alt="{{ child.title }}" src="{{ showcase_image }}" />
                </div>
                {% endif %} 

                <div class="media-object-section"> 
                    <h5><a href="{{ child.url }}">{% if child.menu %},{{ child.menu }},{% else %},{{ child.title }},{% endif %}</a></h5>
                </div>
            </div>
            {% endfor %}

Thanks :)

10 years ago

@rhukster so we have:

{{ page.header.date }} <- by setting manually date in header
{{ page.header.modified_date }} <- its built in
{{ page.header.publish_date }} <- its built in but it seems like it is same as date I can set manually?

Is that correct?

10 years ago

I would say that date is equal to modified_date when not set manually and equals to the file's last modified date on system.

10 years ago

published_date is really intenteded for future publishing. ie. you create a post today, but set published_date for next week. it won't show up until that published_date is passed.

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1357 9 years ago
Archive · by Muut Archive, 9 years ago
2 936 9 years ago
Archive · by Muut Archive, 9 years ago
2 4066 9 years ago
Archive · by Muut Archive, 9 years ago
1 2955 9 years ago
Archive · by Muut Archive, 9 years ago
3 1121 9 years ago