🤩 File Manager - Mr.X
PHP:
8.3.33
Server:
Apache
OS:
Linux 5.14.0-611.49.1.el9_7.x86_64
User:
websparkit
Navigate
Upload:
Upload
New File
New Folder
Editing:category.php
<?php require_once __DIR__ . '/../includes/config.php'; require_once __DIR__ . '/../includes/db.php'; require_once __DIR__ . '/../includes/functions.php'; $page = 'category'; $slug = $_GET['slug'] ?? ''; $stmt = $db->prepare("SELECT * FROM categories WHERE slug = ? AND status = 1"); $stmt->execute([$slug]); $category = $stmt->fetch(); if (!$category) { header('Location: ' . SITE_URL . 'pages/shop.php'); exit; } $page_title = $category['name']; // Get subcategories $subcategories = get_subcategories($category['id']); // Get products $page_num = max(1, intval($_GET['page'] ?? 1)); $per_page = 12; $offset = ($page_num - 1) * $per_page; $sort = $_GET['sort'] ?? 'newest'; $order_by = match($sort) { 'price_low' => 'p.regular_price ASC', 'price_high' => 'p.regular_price DESC', 'name' => 'p.name ASC', default => 'p.created_at DESC' }; $count_stmt = $db->prepare("SELECT COUNT(*) FROM products WHERE category_id = ? AND status = 1"); $count_stmt->execute([$category['id']]); $total_products = $count_stmt->fetchColumn(); $total_pages = ceil($total_products / $per_page); $products_stmt = $db->prepare("SELECT p.*, c.name as category_name, c.slug as category_slug FROM products p LEFT JOIN categories c ON p.category_id = c.id WHERE p.category_id = ? AND p.status = 1 ORDER BY $order_by LIMIT $per_page OFFSET $offset"); $products_stmt->execute([$category['id']]); $products = $products_stmt->fetchAll(); require_once '../includes/header.php'; require_once '../includes/navbar.php'; ?> <main> <!-- Category Hero --> <section class="category-hero" style="background: var(--gradient-soft); padding: 80px 0; text-align: center;"> <div class="container"> <div class="category-icon-large" style="width: 80px; height: 80px; background: var(--white); color: var(--primary-rose-gold); border-radius: 50%; display: flex; align-items: center; justify-content: center; margin: 0 auto 20px; font-size: 2rem; box-shadow: var(--shadow-md);"> <i class="<?= $category['icon'] ?? 'fas fa-tag' ?>"></i> </div> <h1 style="font-size: 3rem; margin-bottom: 15px;"><?= htmlspecialchars($category['name']) ?></h1> <p style="font-size: 1.1rem; color: var(--gray-700); max-width: 600px; margin: 0 auto 30px;"> <?= htmlspecialchars($category['description'] ?? '') ?> </p> <p style="color: var(--gray-600); margin: 0;"><?= $total_products ?> products available</p> </div> </section> <!-- Subcategories --> <?php if (count($subcategories) > 0): ?> <section style="padding: 30px 0; background: var(--white);"> <div class="container"> <div class="d-flex flex-wrap gap-2 justify-content-center"> <a href="<?= SITE_URL ?>pages/category.php?slug=<?= $category['slug'] ?>" class="btn-luxury" style="padding: 8px 20px; font-size: 0.85rem; background: var(--primary-rose-gold); border-radius: 50px;"> All </a> <?php foreach ($subcategories as $sub): ?> <a href="<?= SITE_URL ?>pages/shop.php?subcategory=<?= $sub['id'] ?>" class="btn-outline-luxury" style="padding: 8px 20px; font-size: 0.85rem; border-radius: 50px; border: 1px solid var(--gray-300);"> <?= htmlspecialchars($sub['name']) ?> </a> <?php endforeach; ?> </div> </div> </section> <?php endif; ?> <!-- Products --> <section style="padding: 60px 0;"> <div class="container"> <div class="d-flex justify-content-between align-items-center mb-4 flex-wrap gap-2"> <p class="text-muted mb-0">Showing <?= $offset + 1 ?>-<?= min($offset + $per_page, $total_products) ?> of <?= $total_products ?> products</p> <select class="form-select" onchange="window.location.href=this.value" style="border-radius: 25px; padding: 8px 20px; max-width: 250px;"> <option value="?<?= http_build_query(array_merge($_GET, ['sort' => 'newest', 'page' => 1])) ?>" <?= $sort == 'newest' ? 'selected' : '' ?>>Sort by: Newest</option> <option value="?<?= http_build_query(array_merge($_GET, ['sort' => 'price_low', 'page' => 1])) ?>" <?= $sort == 'price_low' ? 'selected' : '' ?>>Price: Low to High</option> <option value="?<?= http_build_query(array_merge($_GET, ['sort' => 'price_high', 'page' => 1])) ?>" <?= $sort == 'price_high' ? 'selected' : '' ?>>Price: High to Low</option> <option value="?<?= http_build_query(array_merge($_GET, ['sort' => 'name', 'page' => 1])) ?>" <?= $sort == 'name' ? 'selected' : '' ?>>Name: A to Z</option> </select> </div> <?php if (count($products) > 0): ?> <div class="product-grid"> <?php foreach ($products as $product): ?> <?php include '../includes/product-card.php'; ?> <?php endforeach; ?> </div> <?php if ($total_pages > 1): ?> <div class="mt-5"> <nav> <ul class="pagination justify-content-center"> <?php if ($page_num > 1): ?> <li class="page-item"> <a class="page-link" href="?<?= http_build_query(array_merge($_GET, ['page' => $page_num - 1])) ?>" style="border-radius: 50%; margin: 0 5px; width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; border: 1px solid var(--gray-300); color: var(--dark-text);"> <i class="fas fa-chevron-left"></i> </a> </li> <?php endif; ?> <?php for ($i = max(1, $page_num - 2); $i <= min($total_pages, $page_num + 2); $i++): ?> <li class="page-item <?= $i == $page_num ? 'active' : '' ?>"> <a class="page-link" href="?<?= http_build_query(array_merge($_GET, ['page' => $i])) ?>" style="border-radius: 50%; margin: 0 5px; width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; <?= $i == $page_num ? 'background: var(--gradient-rose); border-color: var(--primary-rose-gold); color: var(--white);' : 'border: 1px solid var(--gray-300); color: var(--dark-text);' ?>"> <?= $i ?> </a> </li> <?php endfor; ?> <?php if ($page_num < $total_pages): ?> <li class="page-item"> <a class="page-link" href="?<?= http_build_query(array_merge($_GET, ['page' => $page_num + 1])) ?>" style="border-radius: 50%; margin: 0 5px; width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; border: 1px solid var(--gray-300); color: var(--dark-text);"> <i class="fas fa-chevron-right"></i> </a> </li> <?php endif; ?> </ul> </nav> </div> <?php endif; ?> <?php else: ?> <div class="text-center py-5" style="background: var(--white); border-radius: 16px;"> <i class="fas fa-box-open" style="font-size: 4rem; color: var(--soft-pink); margin-bottom: 20px;"></i> <h3>No products in this category yet</h3> <p class="text-muted">Check back soon for new arrivals</p> <a href="<?= SITE_URL ?>pages/shop.php" class="btn-luxury mt-3">Browse All Products</a> </div> <?php endif; ?> </div> </section> </main> <?php require_once '../includes/footer.php'; ?>
Save Changes
Cancel
Create New File
Create New Folder