🚀 Hostinger Optimized
🖥️ Server: LiteSpeed
💻 System: Linux s20058.bom1.stableserver.net 5.14.0-611.55.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Tue May 19 15:19:29 EDT 2026 x86_64
👤 User: skhata (1324)
🐘 PHP: 8.4.20
🚫 Disabled: ✨ NONE

💻 Terminal

📁 /home/skhata/chandrasons.com/public
$

📄 blogs.php

📁 Path: /home/skhata/excellenteducation.com.np/admin/blogs.php
📊 Size: 3.33 KB
🔒 Perm: 0644
📝 MIME: text/x-php
<?php
require_once __DIR__ . '/../includes/auth.php';
require_login();
$pageTitle = 'Blog Posts';

if ($_SERVER['REQUEST_METHOD'] === 'POST' && ($_POST['action'] ?? '') === 'delete' && csrf_verify()) {
    $id = (int) ($_POST['id'] ?? 0);
    $find = db()->prepare('SELECT slug FROM blogs WHERE id = ?');
    $find->execute([$id]);
    if ($slug = $find->fetchColumn()) {
        $stub = __DIR__ . '/../blog-' . $slug . '.php';
        if (is_file($stub)) @unlink($stub);
    }
    $stmt = db()->prepare('DELETE FROM blogs WHERE id = ?');
    $stmt->execute([$id]);
    flash_set('success', 'Blog post deleted.');
    redirect('blogs.php');
}

$posts = db()->query('SELECT b.*, c.name AS category_name FROM blogs b LEFT JOIN blog_categories c ON c.id = b.category_id ORDER BY b.published_at DESC, b.id DESC')->fetchAll();

require __DIR__ . '/partials/header.php';
require __DIR__ . '/partials/sidebar.php';
require __DIR__ . '/partials/topbar.php';
?>

<div class="flex items-center justify-between mb-5">
  <p class="text-gray-500 text-sm"><?= count($posts) ?> posts</p>
  <a href="blog_form.php" class="bg-gradient-to-r from-brand-red to-brand-green text-white text-sm font-semibold px-5 py-2.5 rounded-xl hover:brightness-110 transition">
    <i class="fa-solid fa-plus mr-1"></i> Add New Post
  </a>
</div>

<div class="bg-white rounded-2xl shadow-sm overflow-hidden">
  <div class="overflow-x-auto">
    <table class="w-full text-sm">
      <thead class="bg-gray-50"><tr class="text-left text-gray-400">
        <th class="px-5 py-3 font-medium">Title</th>
        <th class="px-5 py-3 font-medium">Category</th>
        <th class="px-5 py-3 font-medium">Published</th>
        <th class="px-5 py-3 font-medium">Status</th>
        <th class="px-5 py-3 font-medium text-right">Actions</th>
      </tr></thead>
      <tbody>
        <?php foreach ($posts as $p): ?>
        <tr class="border-t border-gray-100 hover:bg-gray-50/60">
          <td class="px-5 py-3 font-medium"><?= e($p['title']) ?></td>
          <td class="px-5 py-3 text-gray-500"><?= e($p['category_name'] ?? '—') ?></td>
          <td class="px-5 py-3 text-gray-500"><?= $p['published_at'] ? e(date('d M Y', strtotime($p['published_at']))) : '—' ?></td>
          <td class="px-5 py-3"><span class="px-2.5 py-1 rounded-full text-xs font-medium <?= $p['status'] === 'published' ? 'bg-brand-green/10 text-brand-green' : 'bg-gray-200 text-gray-500' ?>"><?= e(ucfirst($p['status'])) ?></span></td>
          <td class="px-5 py-3 text-right whitespace-nowrap">
            <a href="../blog-<?= e($p['slug']) ?>.php" target="_blank" class="text-gray-400 hover:text-gray-600 mr-3"><i class="fa-solid fa-eye"></i></a>
            <a href="blog_form.php?id=<?= (int) $p['id'] ?>" class="text-brand-green hover:text-green-700 mr-3"><i class="fa-solid fa-pen-to-square"></i></a>
            <form method="post" class="inline" onsubmit="return confirm('Delete this post?');">
              <?= csrf_field() ?>
              <input type="hidden" name="action" value="delete">
              <input type="hidden" name="id" value="<?= (int) $p['id'] ?>">
              <button type="submit" class="text-brand-red hover:text-red-700"><i class="fa-solid fa-trash"></i></button>
            </form>
          </td>
        </tr>
        <?php endforeach; ?>
      </tbody>
    </table>
  </div>
</div>

<?php require __DIR__ . '/partials/footer.php'; ?>
← Back📥 Raw✏️ Edit🔒 Chmod
✨ File Manager Magic ✨