56 lines
1.5 KiB
PHP
56 lines
1.5 KiB
PHP
<?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();
|
|
?>
|
|
|
|
<!DOCTYPE html>
|
|
<html lang="fr">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>Accueil - Un CMS Quoi</title>
|
|
<link rel="stylesheet" href="assets/style.css">
|
|
</head>
|
|
<body>
|
|
|
|
<header>
|
|
<!-- Menu de navigation -->
|
|
<nav>
|
|
<a href="index.php">Accueil</a> |
|
|
<a href="admin/connexion.php">Administration</a>
|
|
</nav>
|
|
</header>
|
|
|
|
<main>
|
|
<h1>Articles Publiés</h1>
|
|
|
|
<?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>© <?= date("Y") ?> - Un CMS simple et efficace</p>
|
|
</footer>
|
|
|
|
</body>
|
|
</html>
|