While this code works fine, it seems to me that I should be sorting by “created” date, not “modified” date. You would think that sorting by the “modified” key would return a list of the most recently modified or edited pages, rather than the most recently created pages.
Likewise, the following code returns the page’s creation date, not it’s modified date:
<?php echo $latest->modified('d F Y') ?>
Is this the way Kirby is supposed to return date information related to pages? Or am I missing something?
I’m not modifying any files through the Panel, which I am assuming is calling the update() and touch() functions. I’m editing everything locally and FTP’ing to the server. Would that make any difference?
Hmmm … I don’t think that would work. If I turn off “Preserve modification dates” then the modification date becomes the date the file was uploaded to the server, which isn‘t always the case. Sometimes I simply move a file to a different directory, which shouldn’t affect the date which the file itself was modified.
it also means that if you upload a file the modification date of the file on the server is kept, right? it will keep the first mod-date forever, right?
so are you sure the modification dates on the server match your expected sorting order?
Please note that Kirby reads the modification date from the page’s directory, not from the content file. The reason is that e.g. if you upload a new image, the page is still modified even though the content file stays the same.
To make the modified value work, you need to touch the directory or tell your FTP program to do so on every change. Kirby can’t magically determine the date of last modification without the help of the file system.
This is getting way more complicated than it should be. I think the best way to avoid any modification (or creation) date issues is to include a fixed “created date” field in each new file and used that as the sort key.