Ajouter public/index.php
This commit is contained in:
55
public/index.php
Normal file
55
public/index.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../src/db.php';
|
||||
require_once __DIR__ . '/../src/functions.php';
|
||||
$perPage = 10;
|
||||
$page = isset($_GET['p']) ? max(1, (int)$_GET['p']) : 1;
|
||||
$offset = ($page - 1) * $perPage;
|
||||
$totalStmt = $pdo->query('SELECT COUNT(*) FROM articles');
|
||||
$total = (int)$totalStmt->fetchColumn();
|
||||
$pages = max(1, ceil($total / $perPage));
|
||||
$stmt = $pdo->prepare('SELECT id, titre, contenu, date_creation FROM articles ORDER BY date_creation DESC LIMIT :lim OFFSET :off');
|
||||
$stmt->bindValue(':lim', $perPage, PDO::PARAM_INT);
|
||||
$stmt->bindValue(':off', $offset, PDO::PARAM_INT);
|
||||
$stmt->execute();
|
||||
$articles = $stmt->fetchAll();
|
||||
?>
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>CMS Simplifié - Accueil</title>
|
||||
<link rel="stylesheet" href="/public/assets/style.css">
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<h1>CMS Simplifié</h1>
|
||||
<nav>
|
||||
<a href="/public/index.php">Accueil</a>
|
||||
<a href="/public/login.php">Admin</a>
|
||||
</nav>
|
||||
</header>
|
||||
<main>
|
||||
<h2>Articles</h2>
|
||||
<?php if (empty($articles)): ?>
|
||||
<p>Aucun article publié.</p>
|
||||
<?php else: ?>
|
||||
<?php foreach ($articles as $a): ?>
|
||||
<article>
|
||||
<h3><a href="/public/article.php?id=<?php echo (int)$a['id']; ?>"><?php echo esc($a['titre']); ?></a></h3>
|
||||
<p class="article-intro"><?php echo nl2br(esc(mb_substr($a['contenu'], 0, 300))); ?>...</p>
|
||||
<small>Publié le <?php echo esc($a['date_creation']); ?></small>
|
||||
</article>
|
||||
<hr>
|
||||
<?php endforeach; ?>
|
||||
<nav aria-label="pagination">
|
||||
<?php if ($page > 1): ?><a href="?p=<?php echo $page-1; ?>">« Précédent</a><?php endif; ?>
|
||||
Page <?php echo $page; ?> / <?php echo $pages; ?>
|
||||
<?php if ($page < $pages): ?><a href="?p=<?php echo $page+1; ?>">Suivant »</a><?php endif; ?>
|
||||
</nav>
|
||||
<?php endif; ?>
|
||||
</main>
|
||||
<footer>
|
||||
<p>© CMS Simplifié</p>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user