prepare("SELECT * FROM tags WHERE id=?"); $t->execute([$id]); $tg = $t->fetch(); if (!$tg) { header("Location: " . SITE_URL . "index.php"); exit; } $pageName = "tag"; $pageTitle = $tg["name"]; record_visit("tag/" . $id); $perPage = 5; $st = db()->prepare("SELECT COUNT(*) c FROM article_tags WHERE tag_id=?"); $st->execute([$id]); $pg = paginate((int)$st->fetch()["c"], isset($_GET["page"])?(int)$_GET["page"]:1, $perPage); $stmt = db()->prepare("SELECT a.*, c.name cat_name FROM articles a JOIN article_tags at ON a.id=at.article_id LEFT JOIN categories c ON a.category_id=c.id WHERE at.tag_id=? AND a.status=? ORDER BY a.created_at DESC LIMIT ? OFFSET ?"); $stmt->bindValue(1,$id,PDO::PARAM_INT); $stmt->bindValue(2,"published",PDO::PARAM_STR); $stmt->bindValue(3,$pg["perPage"],PDO::PARAM_INT); $stmt->bindValue(4,$pg["offset"],PDO::PARAM_INT); $stmt->execute(); $articles = $stmt->fetchAll(); require_once __DIR__ . "/includes/header.php"; ?>