Update index.php

This commit is contained in:
deepend-tildeclub 2024-08-17 08:55:28 -06:00 committed by GitHub
parent dcbd902aaa
commit 217b00b6e6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 15 additions and 14 deletions

View File

@ -23,22 +23,24 @@
$filteredNews = []; $filteredNews = [];
$currentDate = new DateTime(); $currentDate = new DateTime();
if ($selectedYear) {
// Filter news by selected year
foreach ($news as $newsItem) { foreach ($news as $newsItem) {
$newsDate = new DateTime($newsItem['date']);
// Only add to filteredNews if the current date is on or after the news date
if ($newsDate <= $currentDate) {
if ($selectedYear) {
// If filtering by year, add items from the selected year only
if (date('Y', strtotime($newsItem['date'])) == $selectedYear) { if (date('Y', strtotime($newsItem['date'])) == $selectedYear) {
$filteredNews[] = $newsItem; $filteredNews[] = $newsItem;
} }
}
} else { } else {
// Show only the most recent 2 news items if no year filter is applied // Otherwise, show the most recent 2 items
foreach ($news as $newsItem) {
if (new DateTime($newsItem['date']) <= $currentDate) {
$filteredNews[] = $newsItem; $filteredNews[] = $newsItem;
} }
if (count($filteredNews) >= 2) {
break;
} }
if (!$selectedYear && count($filteredNews) >= 2) {
break;
} }
} }
@ -81,7 +83,6 @@
?> ?>
</div> </div>
<div class="col"> <div class="col">
<p> <p>
tilde.club is not a social network it is one tiny totally tilde.club is not a social network it is one tiny totally