query('SELECT id, part, title, summary, updated_at FROM articles WHERE enabled = 1 ORDER BY updated_at DESC, id DESC')->fetchAll(); $byPart = []; foreach ($all as $r) { $part = trim((string)$r['part']); if ($part === '') { $part = '未分类'; } $byPart[$part][] = $r; } // 分区顺序:后台「文章管理」拖出的分区顺序(article_part_order)优先;未配置则按各分区最新更新时间降序 $poIdx = []; $poCfg = trim((string)setting_get('article_part_order', '')); if ($poCfg !== '') { foreach (explode(',', $poCfg) as $po) { $po = trim($po); if ($po !== '' && isset($byPart[$po])) $poIdx[$po] = count($poIdx); } } $partKeys = array_keys($byPart); usort($partKeys, static function (string $a, string $b) use ($poIdx, $byPart): int { $ia = $poIdx[$a] ?? PHP_INT_MAX; $ib = $poIdx[$b] ?? PHP_INT_MAX; if ($ia !== $ib) return $ia <=> $ib; // 各分区首篇即最新(SQL 已按 updated_at 倒序) $d = strcmp((string)$byPart[$b][0]['updated_at'], (string)$byPart[$a][0]['updated_at']); return $d !== 0 ? $d : strcmp($a, $b); }); $rows = []; foreach ($partKeys as $p) { $rows[] = ['part' => $p, 'articles' => $byPart[$p]]; } $total = count($all); // 从库首页“文章区”卡片进入阅读时(?from=nav),顶部返回按钮语义切换 $fromNav = (isset($_GET['from']) && (string)$_GET['from'] === 'nav'); // 当前阅读文章 $cur = null; $cid = (int)($_GET['id'] ?? 0); if ($cid > 0) { $st = $pdo->prepare('SELECT * FROM articles WHERE id = ? AND enabled = 1 LIMIT 1'); $st->execute([$cid]); $cur = $st->fetch(); if (!$cur) { $cur = null; // 无效或已隐藏:回退到列表 } } layout_head($cur ? (string)$cur['title'] : '文章库'); ?>
= he(trim((string)$cur['summary'])) ?>
点击任意文章开始阅读;左侧「文章目录」可随时切换文章,中间「段落目录」可快速跳转。
文章库还没有内容,站长可在后台「文章管理」中发布。