From 099ebc059f1088eed124f2cbce8c7370d0f2dec3 Mon Sep 17 00:00:00 2001 From: Mohamad Damaj Date: Mon, 26 Jun 2023 11:16:02 +0300 Subject: [PATCH] Fix date format and implement dates in previews --- site/blog/index.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/site/blog/index.php b/site/blog/index.php index 0a686c2..ef94ee4 100644 --- a/site/blog/index.php +++ b/site/blog/index.php @@ -26,7 +26,9 @@ $items = iterator_to_array($xml->channel->item); // Sort the items by pubDate usort($items, function($a, $b) { - return strtotime($b->pubDate) - strtotime($a->pubDate); + $a_time = DateTime::createFromFormat('D, d M Y H:i:s O', $a->pubDate)->getTimestamp(); + $b_time = DateTime::createFromFormat('D, d M Y H:i:s O', $b->pubDate)->getTimestamp(); + return $b_time - $a_time; }); // Loop through the sorted items and display them @@ -34,8 +36,9 @@ foreach ($items as $item) { // Add a box around the article echo '
'; - // Highlight the title + // Highlight the title and date echo '

' . $item->title . '

'; + echo '

' . date('F j, Y', strtotime($item->pubDate)) . '

'; // Split the content into sentences $sentences = preg_split('/(?<=[.?!])\s+(?=[a-z])/i', $item->description);