32 lines
823 B
PHP
32 lines
823 B
PHP
<?php
|
|
include 'includes/header.php';
|
|
|
|
include 'includes/db.php';
|
|
?>
|
|
|
|
<main>
|
|
<h2>Derniers articles</h2>
|
|
|
|
<?php
|
|
$sql = "SELECT * FROM articles ORDER BY date_creation DESC LIMIT 10";
|
|
$stmt = $pdo->prepare($sql);
|
|
$stmt->execute();
|
|
$articles = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
if ($articles) {
|
|
foreach ($articles as $article) {
|
|
echo '<article>';
|
|
echo '<h3>' . htmlspecialchars($article['titre']) . '</h3>';
|
|
echo '<p>' . substr(htmlspecialchars($article['contenu']), 0, 100) . '...</p>';
|
|
echo '<a href="article.php?id=' . $article['id'] . '">Lire la suite</a>';
|
|
echo '</article><hr>';
|
|
}
|
|
} else {
|
|
echo "<p>Aucun article publié pour le moment.</p>";
|
|
}
|
|
?>
|
|
</main>
|
|
|
|
<?php
|
|
include 'includes/footer.php';
|
|
?>
|