Bài Viết Phổ Biến

prepare(" SELECT p.id, p.title, p.content, p.category, p.created_at, p.views, COUNT(c.id) AS comment_count, COUNT(l.id) AS like_count FROM posts p LEFT JOIN comments c ON p.id = c.post_id LEFT JOIN likes l ON p.id = l.post_id GROUP BY p.id ORDER BY (p.views + COUNT(l.id) + COUNT(c.id)) DESC LIMIT 3 "); $stmt->execute(); $popular_posts = $stmt->fetchAll(); foreach ($popular_posts as $post) { $placeholder_img = 'https://images.unsplash.com/photo-1542744173-8e7e53415bb0?auto=format&fit=crop&w=800&q=80'; // Có thể tùy chỉnh echo ' '; } if (empty($popular_posts)) { echo '

Chưa có bài viết phổ biến nào.

'; } } catch (PDOException $e) { error_log("Index popular posts error: " . $e->getMessage()); echo '

Lỗi tải bài viết phổ biến.

'; } ?>