dernier modif

This commit is contained in:
2025-11-02 23:39:25 +01:00
parent 296b5c5a62
commit d4a982d80e
8 changed files with 182 additions and 113 deletions

View File

@@ -1,12 +1,14 @@
<?php
// Page d'accueil affichant les 10 derniers articles
include 'include/db.php';
// Récupération des 10 derniers articles, triés par date décroissante
$sql = "SELECT * FROM articles ORDER BY date_creation DESC LIMIT 10";
$result = $pdo->query($sql);
$articles = $result->fetchAll();
?>
<!-- Page Principal -->
<!DOCTYPE html>
<html lang="fr">
<head>
@@ -17,8 +19,9 @@ $articles = $result->fetchAll();
<body>
<header>
<!-- Menu de navigation -->
<nav>
<a href="index.php">Un Accueil qui Accueil</a> |
<a href="index.php">Accueil</a> |
<a href="admin/connexion.php">Administration</a>
</nav>
</header>
@@ -26,25 +29,27 @@ $articles = $result->fetchAll();
<main>
<h1>Articles Publiés</h1>
<?php
if (count($articles) == 0) {
echo "<p>Aucun article trouvé pour le moment.</p>";
} else {
foreach ($articles as $a) {
echo "<article>";
echo "<h2><a href='article.php?id=" . $a['id'] . "'>" . htmlspecialchars($a['titre']) . "</a></h2>";
echo "<small>Publie le " . date("d/m/Y", strtotime($a['date_creation'])) . "</small>";
echo "<p>" . substr(htmlspecialchars($a['contenu']), 0, 200) . "...</p>";
echo "<p><a href='article.php?id=" . $a['id'] . "'>Lire la suite</a></p>";
echo "</article>";
}
}
?>
<?php if (count($articles) === 0): ?>
<p>Aucun article trouvé pour le moment.</p>
<?php else: ?>
<?php foreach ($articles as $a): ?>
<article>
<h2>
<a href="article.php?id=<?= $a['id'] ?>">
<?= htmlspecialchars($a['titre']) ?>
</a>
</h2>
<small>Publié le <?= date("d/m/Y", strtotime($a['date_creation'])) ?></small>
<p><?= htmlspecialchars(substr($a['contenu'], 0, 200)) ?>...</p>
<p><a href="article.php?id=<?= $a['id'] ?>">Lire la suite</a></p>
</article>
<?php endforeach; ?>
<?php endif; ?>
</main>
<footer>
<p>&copy; <?php echo date("Y"); ?> - Un CMS simple et efficace</p>
<p>&copy; <?= date("Y") ?> - Un CMS simple et efficace</p>
</footer>
</body>
</html>
</html>