init: 我的博客项目
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
require_once __DIR__ . "/includes/config.php";
|
||||
require_once __DIR__ . "/includes/functions.php";
|
||||
$id = isset($_GET["id"]) ? (int)$_GET["id"] : 0;
|
||||
$t = db()->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";
|
||||
?>
|
||||
<div class="page-head">
|
||||
<h1>标签: <?php echo e($tg["name"]); ?></h1>
|
||||
<div class="desc">该标签下的文章</div>
|
||||
</div>
|
||||
<?php if (!$articles) { ?><div class="card glass" style="text-align:center;color:var(--text-muted);padding:60px;">该标签暂无文章</div><?php } ?>
|
||||
<?php foreach ($articles as $a) { ?>
|
||||
<article class="card glass clickable" onclick="location.href='<?php echo e(SITE_URL); ?>article.php?id=<?php echo (int)$a["id"]; ?>'">
|
||||
<div class="card-meta"><span class="glass-chip"><?php echo e($a["cat_name"] ?: "未分类"); ?></span><span><?php echo e(substr($a["created_at"],0,10)); ?></span></div>
|
||||
<h2><?php echo e($a["title"]); ?></h2>
|
||||
</article>
|
||||
<?php } ?>
|
||||
<?php if ($pg["pages"]>1) { ?><div class="pagination"><?php for($i=1;$i<=$pg["pages"];$i++){ ?><a class="page-btn<?php echo $i===$pg["page"]?" active":""; ?>" href="?id=<?php echo $id; ?>&page=<?php echo $i; ?>"><?php echo $i; ?></a><?php } ?></div><?php } ?>
|
||||
<?php require_once __DIR__ . "/includes/footer.php"; ?>
|
||||
Reference in New Issue
Block a user