37301-vm/blog.php
Flatlogic Bot 9bf0056520 test
2026-01-07 09:28:17 +00:00

51 lines
2.2 KiB
PHP

<?php
$pageTitle = "Our Blog";
$pageDescription = "Latest news, articles, and insights from the world of luxury carpets and interior design.";
require_once __DIR__ . '/includes/header.php';
require_once __DIR__ . '/db/config.php';
// Fetch all posts from the database
$posts = [];
try {
$pdo = db();
$stmt = $pdo->query("SELECT id, title, slug, content, author, image_url, published_at FROM posts ORDER BY published_at DESC");
$posts = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
error_log('Failed to fetch posts: ' . $e->getMessage());
}
?>
<main class="container mt-5">
<div class="row">
<div class="col-12 text-center mb-5">
<h1 class="display-4">From the Journal</h1>
<p class="lead">Design insights, company news, and the art of craftsmanship.</p>
</div>
</div>
<div class="row">
<?php if (empty($posts)): ?>
<div class="col-12">
<p class="text-center">No articles have been published yet. Please check back soon.</p>
</div>
<?php else: ?>
<?php foreach ($posts as $post): ?>
<div class="col-md-6 mb-4">
<div class="card h-100 shadow-sm blog-card">
<img src="<?php echo htmlspecialchars($post['image_url'] ?? 'https://picsum.photos/800/600'); ?>" class="card-img-top" alt="<?php echo htmlspecialchars($post['title']); ?>">
<div class="card-body d-flex flex-column">
<h5 class="card-title"><?php echo htmlspecialchars($post['title']); ?></h5>
<p class="card-text text-muted">By <?php echo htmlspecialchars($post['author']); ?> on <?php echo date("F j, Y", strtotime($post['published_at'])); ?></p>
<p class="card-text"><?php echo substr(htmlspecialchars(strip_tags($post['content'])), 0, 120); ?>...</p>
<a href="post.php?slug=<?php echo htmlspecialchars($post['slug']); ?>" class="btn btn-outline-primary mt-auto">Read More</a>
</div>
</div>
</div>
<?php endforeach; ?>
<?php endif; ?>
</div>
</main>
<?php require_once __DIR__ . '/includes/footer.php'; ?>