I’m new around here and in many ways still inexperienced, so please bear with me.
I’m trying to set up a blog with the latest version of Kirby. The blog requires a proper way to show the date and time the entry was posted. I haven’t touched the respective Kirby fields.
The theme always gets the date right, but not the time, which remains at midnight. Within the panel, the correct time is given (it’s a fairly odd one, not midnight).
I have a RSS feed as well, which also sticks to midnight, so I don’t think the theme has to do with the issue. Or does it?
Ah, good question! As far as time is concerned, I have added a blueprint, which results in separate fields on the panel for the date and the time. Now, as soon I write a blog entry, the text file includes this:
Date: 2015-06-15
----
Time: 18:54
The blog itself would show everything as expected if the time was added to the “Date:” section:
Date: 2015-06-15 18:54
How do I get the blueprint to create the blog entry correctly?
You need those two separate fields, that is correct. But in your template, you only call the date, which does not contain the time or is rather set to midnight. To show the date, simply echo the time field:
Amazing, it’s as easy as this, thank you! Really appreciate your quick and competent help, guys!
The only thing left to correct would be the feed, which is generated by Bastian’s plugin. Where am I to edit either the feed.php and/or the template.php?
I finally came up with the solution, thanks to being sleep-deprived, which provided a much-needed sense of clarity. Aww, you know that!
In the feed.php, I have defined a new default:
'timefield' => 'time',
This ensures that a separate field for the time within a blog post can be processed properly.
Now, looking at the template.php, line 8 does not need to be rewritten. It apparently generates the information when the feed itself was refreshed.
Line 20, however, is key. It fetches the information from the date field of the blog post and displays it in accordance to RFC 2822 (example: Thu, 21 Dec 2000 16:01:07 +0200). All I had to do is rebuild this structure piece by piece. This allows me to jump to another echo (if that makes sense), from date to time:
<pubDate><?php echo $datefield == 'modified' ? $item->modified('D, d M Y') : $item->date('D, d M Y', $datefield) ?> <?php echo $timefield == 'modified' ? $item->modified('H:i:s O') : $item->time('H:i:s O', $timefield) ?></pubDate>
That’s exactly what I meant. But I had another idea, just haven’t had the time to test this, i.e. using a page model to combine both date and time fields into a single field value and then go from there.