Hi @stefanzweifel, thank you very much for the plugin! It really is great to be at the forefront of something new…
Now, I encountered an issue similar to Bastian’s XML feed plugin: The respective date of the entry is correct, but the time is not, it’s always midnight. This is due to the fact that I have separate fields for each of my blog entries: “date” and “time.” Is there a way to combine them either in the template or the json-feed.php file?
Many thanks in advance!
@insintesi you could use the technique @texnixe mentioned and then update the date_published
field in json-feed.php
to use the combined date.
I’m currently on a client project and hope to release a better version of the json-feed plugin after that project.
I’m sorry to bother again, but I haven’t managed to implement the separate time field successfully. Could anyone please tell me how to modify the date_published exactly and how to insert the combined isoDate from @texnixe?
<?php
Pages::$methods['jsonfeed'] = function ($pages, $params = []) {
// set all default values
$defaults = [
'title' => 'Feed',
'feed' => url(),
'datefield' => 'date',
'textfield' => 'text',
'timefield' => 'time',
];
// merge them with the user input
$options = array_merge($defaults, $params);
$items = [];
foreach ($pages as $item) {
$items[] = [
'id' => $item->url(),
'url' => $item->url(),
'title' => $item->title()->value(),
'content_html' => $item->{$options['textfield']}()->kirbytext()->value,
'date_published' => $item->date('c', $options['datefield']),
];
}
// Set the Header
header::type('application/json');
// Build the response
$feed = [
'version' => 'https://jsonfeed.org/version/1',
'title' => $options['title'],
'home_page_url' => url(),
'feed_url' => $options['feed'],
'items' => $items,
];
return json_encode($feed);
};
$options[‘datefield’] just gives you the name of the field.
<?php
$date = $item->date('Y-m-d', $options['datefield']);
$time = $item->{$options['timefield']};
$isoDate = date('c', strtotime("$date $time"));