init: 我的博客项目
This commit is contained in:
+35
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
require_once __DIR__ . "/includes/config.php";
|
||||
require_once __DIR__ . "/includes/functions.php";
|
||||
$pageName = "search";
|
||||
$pageTitle = "搜索";
|
||||
record_visit("search");
|
||||
$q = isset($_GET["q"]) ? trim($_GET["q"]) : "";
|
||||
$articles = [];
|
||||
if ($q !== "") {
|
||||
$like = "%" . $q . "%";
|
||||
$st = db()->prepare("SELECT a.*, c.name cat_name FROM articles a LEFT JOIN categories c ON a.category_id=c.id WHERE a.status=? AND (a.title LIKE ? OR a.content LIKE ? OR a.excerpt LIKE ?) ORDER BY a.created_at DESC");
|
||||
$st->execute(["published",$like,$like,$like]);
|
||||
$articles = $st->fetchAll();
|
||||
}
|
||||
require_once __DIR__ . "/includes/header.php";
|
||||
?>
|
||||
<div class="page-head">
|
||||
<h1>搜索</h1>
|
||||
<div class="desc"><?php echo $q !== "" ? "关键词: " . e($q) . " (找到 " . count($articles) . " 篇)" : "输入关键词搜索文章"; ?></div>
|
||||
</div>
|
||||
<div class="search-row" style="margin:0 0 24px;">
|
||||
<form action="<?php echo e(SITE_URL); ?>search.php" method="get" style="display:flex;gap:10px;width:100%;">
|
||||
<input class="glass-input" name="q" value="<?php echo e($q); ?>" placeholder="搜索文章...">
|
||||
<button class="glass-btn primary">搜索</button>
|
||||
</form>
|
||||
</div>
|
||||
<?php if ($q !== "" && !$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>
|
||||
<p><?php echo e(mb_strimwidth(strip_tags($a["excerpt"] ?: $a["content"]),0,140,"...")); ?></p>
|
||||
</article>
|
||||
<?php } ?>
|
||||
<?php require_once __DIR__ . "/includes/footer.php"; ?>
|
||||
Reference in New Issue
Block a user