mirror of https://github.com/tildeclub/site.git
Update index.php
This commit is contained in:
parent
8c0ccfb1fb
commit
c115370510
76
index.php
76
index.php
|
@ -13,34 +13,66 @@
|
||||||
<?php
|
<?php
|
||||||
$news = json_decode(file_get_contents('news.json'), true);
|
$news = json_decode(file_get_contents('news.json'), true);
|
||||||
|
|
||||||
foreach ($news as $newsItem) {
|
// Sort news items by date, most recent first
|
||||||
if (new DateTime() >= new DateTime($newsItem['date'])) {
|
usort($news, function ($a, $b) {
|
||||||
echo '<h2>' . htmlspecialchars($newsItem['title']) . ':</h2>';
|
return strtotime($b['date']) - strtotime($a['date']);
|
||||||
echo '<h3>' . htmlspecialchars($newsItem['heading']) . '</h3>';
|
});
|
||||||
echo '<p>' . htmlspecialchars($newsItem['content']) . '</p>';
|
|
||||||
|
|
||||||
if (isset($newsItem['details']) && is_array($newsItem['details'])) {
|
// Determine the year filter if present
|
||||||
echo '<ul>';
|
$selectedYear = isset($_GET['year']) ? $_GET['year'] : null;
|
||||||
foreach ($newsItem['details'] as $detail) {
|
$filteredNews = [];
|
||||||
echo '<li>' . htmlspecialchars($detail) . '</li>';
|
|
||||||
}
|
if ($selectedYear) {
|
||||||
echo '</ul>';
|
// Filter news by selected year
|
||||||
|
foreach ($news as $newsItem) {
|
||||||
|
if (date('Y', strtotime($newsItem['date'])) == $selectedYear) {
|
||||||
|
$filteredNews[] = $newsItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($newsItem['note'])) {
|
|
||||||
echo '<p><strong>' . htmlspecialchars($newsItem['note']) . '</strong></p>';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($newsItem['additional_content'])) {
|
|
||||||
echo '<p>' . htmlspecialchars($newsItem['additional_content']) . '</p>';
|
|
||||||
}
|
|
||||||
|
|
||||||
echo '<hr>';
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// Show only the most recent 2 news items if no year filter is applied
|
||||||
|
$filteredNews = array_slice($news, 0, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Display news items
|
||||||
|
foreach ($filteredNews as $newsItem) {
|
||||||
|
echo '<h2>' . htmlspecialchars($newsItem['title']) . ':</h2>';
|
||||||
|
echo '<h3>' . htmlspecialchars($newsItem['heading']) . '</h3>';
|
||||||
|
echo '<p>' . htmlspecialchars($newsItem['content']) . '</p>';
|
||||||
|
|
||||||
|
if (isset($newsItem['details']) && is_array($newsItem['details'])) {
|
||||||
|
echo '<ul>';
|
||||||
|
foreach ($newsItem['details'] as $detail) {
|
||||||
|
echo '<li>' . htmlspecialchars($detail) . '</li>';
|
||||||
|
}
|
||||||
|
echo '</ul>';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($newsItem['note'])) {
|
||||||
|
echo '<p><strong>' . htmlspecialchars($newsItem['note']) . '</strong></p>';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($newsItem['additional_content'])) {
|
||||||
|
echo '<p>' . htmlspecialchars($newsItem['additional_content']) . '</p>';
|
||||||
|
}
|
||||||
|
|
||||||
|
echo '<hr>';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Display year links for filtering
|
||||||
|
$years = array_unique(array_map(function ($newsItem) {
|
||||||
|
return date('Y', strtotime($newsItem['date']));
|
||||||
|
}, $news));
|
||||||
|
sort($years);
|
||||||
|
|
||||||
|
echo '<div><strong>View news by year:</strong> ';
|
||||||
|
foreach ($years as $year) {
|
||||||
|
echo '<a href="?year=' . $year . '">' . $year . '</a> ';
|
||||||
|
}
|
||||||
|
echo '</div>';
|
||||||
?>
|
?>
|
||||||
</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
|
||||||
|
|
Loading…
Reference in New Issue