45 lines
1.6 KiB
PHP
45 lines
1.6 KiB
PHP
<?php
|
|
$pageTitle = 'Home';
|
|
require_once __DIR__ . '/includes/header.php';
|
|
require_once __DIR__ . '/db/config.php';
|
|
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->query("SELECT * FROM posts ORDER BY created_at DESC");
|
|
$posts = $stmt->fetchAll();
|
|
} catch (PDOException $e) {
|
|
die("Error: " . $e->getMessage());
|
|
}
|
|
?>
|
|
|
|
<div class="text-center py-5">
|
|
<h1 class="display-4">Welcome to Our Blog</h1>
|
|
<p class="lead">The latest news and updates, at your fingertips.</p>
|
|
</div>
|
|
|
|
<div class="row">
|
|
<?php if (empty($posts)): ?>
|
|
<div class="col-12">
|
|
<div class="card p-5 text-center">
|
|
<h2>No posts yet!</h2>
|
|
<p>Go to the <a href="/admin.php">admin page</a> to create your first post.</p>
|
|
</div>
|
|
</div>
|
|
<?php else: ?>
|
|
<?php foreach ($posts as $post): ?>
|
|
<div class="col-md-12">
|
|
<div class="card">
|
|
<div class="card-body">
|
|
<h2 class="card-title"><?php echo htmlspecialchars($post['title']); ?></h2>
|
|
<p class="post-meta">By <?php echo htmlspecialchars($post['author']); ?> on <?php echo date('F j, Y', strtotime($post['created_at'])); ?></p>
|
|
<p class="card-text"><?php echo htmlspecialchars(substr($post['content'], 0, 250)); ?>...</p>
|
|
<a href="/post.php?slug=<?php echo htmlspecialchars($post['slug']); ?>" class="btn btn-primary">Read More</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<?php require_once __DIR__ . '/includes/footer.php'; ?>
|