51 lines
2.2 KiB
PHP
51 lines
2.2 KiB
PHP
<?php
|
|
require_once __DIR__ . '/includes/header.php';
|
|
require_once __DIR__ . '/db/config.php';
|
|
|
|
// Fetch all products from the database
|
|
$products = [];
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->query('SELECT id, name, description, images, url_slug, material, application FROM products ORDER BY created_at DESC');
|
|
$products = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
} catch (PDOException $e) {
|
|
error_log('Failed to fetch products: ' . $e->getMessage());
|
|
// You could display a friendly error message to the user
|
|
}
|
|
|
|
?>
|
|
|
|
<main class="container mt-5">
|
|
<div class="row">
|
|
<div class="col-12 text-center mb-5">
|
|
<h1 class="display-4">Our Luxury Carpets</h1>
|
|
<p class="lead">Discover our exclusive collection of hand-crafted carpets and rugs.</p>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="row">
|
|
<?php if (empty($products)): ?>
|
|
<div class="col-12">
|
|
<p class="text-center">No products found. Please check back later.</p>
|
|
</div>
|
|
<?php else: ?>
|
|
<?php foreach ($products as $product): ?>
|
|
<?php $images = json_decode($product['images'], true); ?>
|
|
<div class="col-md-4 mb-4">
|
|
<div class="card h-100 shadow-sm">
|
|
<img src="<?php echo htmlspecialchars($images[0] ?? 'https://picsum.photos/800/600'); ?>" class="card-img-top" alt="<?php echo htmlspecialchars($product['name']); ?>">
|
|
<div class="card-body d-flex flex-column">
|
|
<h5 class="card-title"><?php echo htmlspecialchars($product['name']); ?></h5>
|
|
<p class="card-text text-muted"><?php echo htmlspecialchars($product['material']); ?> | <?php echo htmlspecialchars($product['application']); ?></p>
|
|
<p class="card-text"><?php echo substr(htmlspecialchars($product['description']), 0, 100); ?>...</p>
|
|
<a href="product.php?slug=<?php echo htmlspecialchars($product['url_slug']); ?>" class="btn btn-primary mt-auto">View Details</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</div>
|
|
</main>
|
|
|
|
<?php require_once __DIR__ . '/includes/footer.php'; ?>
|