prepare("SELECT id, title, content, excerpt, image, author, created_at FROM news WHERE id = ? AND status = 'active'"); $stmt->execute([$id]); $article = $stmt->fetch(PDO::FETCH_ASSOC); if (!$article) { header("Location: news.php"); exit; } // Sanitize article data $article['title'] = htmlspecialchars($article['title']); $article['author'] = htmlspecialchars($article['author'] ?? 'NDF Team'); $article['excerpt'] = htmlspecialchars($article['excerpt'] ?? strip_tags(substr($article['content'], 0, 150)) . '...'); // Prepare page-specific meta data for header.php $page_meta_title = $article['title'] . ' - News'; $page_meta_description = $article['excerpt']; $page_meta_image = !empty($article['image']) ? SITE_URL . '/img/' . $article['image'] : ''; $page_url = SITE_URL . '/news-details.php?id=' . $article['id']; // Fetch recent news for sidebar (limit to 5) $stmt = $db->prepare("SELECT id, title, image, created_at FROM news WHERE status = 'active' AND id != ? ORDER BY created_at DESC LIMIT 5"); $stmt->execute([$id]); $recentNews = $stmt->fetchAll(PDO::FETCH_ASSOC); foreach ($recentNews as &$news) { $news['title'] = htmlspecialchars($news['title']); } include 'header.php'; include 'navbar.php'; ?>