e/class/t_functions.php),修改需改核心、升級覆蓋痛苦。itemprop="itemListElement" 等結構化數據。e/class/userfun.php 追加函數<?php
/**
* 自定義當前位置導航
* @param int|string $classid 欄目ID,"selfinfo" 表示自動獲取當前欄目
* @return void 直接輸出 HTML
*/
function user_linknav($classid = 'selfinfo') {
global $empire, $dbtbpre, $navclassid, $class_r, $public_r;
// 1. 確定目標欄目 ID
if ($classid === 'selfinfo') {
$classid = empty($navclassid) ? 0 : $navclassid;
// 終極欄目且有父欄目時,顯示父級作為入口
if ($class_r[$classid]['islast'] && $class_r[$classid]['bclassid']) {
$classid = $class_r[$classid]['bclassid'];
}
}
// 2. 遞歸構建導航鏈(從根到當前)
$crumbs = [];
function build_crumbs($cid) {
global $empire, $dbtbpre, $class_r;
if (!$cid) return;
$row = $empire->fetch1("SELECT classname, bclassid, classpath FROM {$dbtbpre}enewsclass WHERE classid=$cid");
if ($row) {
build_crumbs($row['bclassid']);
$crumbs[] = $row;
}
}
build_crumbs($classid);
// 3. 輸出 HTML(可按需擴展 Schema.org 微數據)
$homeUrl = $public_r['newsurl'];
echo '<nav class="breadcrumb" aria-label="當前位置">';
echo '<a href="' . $homeUrl . '" itemprop="item"><span itemprop="name">首頁</span></a>';
foreach ($crumbs as $i => $cr) {
echo '<span class="sep">></span>';
echo '<a href="' . $homeUrl . $cr['classpath'] . '" itemprop="item">';
echo '<span itemprop="name">' . htmlspecialchars($cr['classname']) . '</span></a>';
}
echo '</nav>';
}
/* 兼容舊調用:若模板仍用 [!--newsnav--],可在 userfun.php 末尾加:
$tempr[newsnav] = user_linknav($GLOBALS['navclassid']);
*/
?>
替換原 [!--newsnav--] 為:
<?= user_linknav($GLOBALS['navclassid']) ?>
或在列表/內容模板中傳入指定欄目 ID:
<?= user_linknav(5) ?> <!-- 強制顯示欄目 5 的導航路徑 -->
在 enewsclass 表新增字段 sub_domain(或利用現有 classpath 存完整 URL),輸出時判斷:
$url = $cr['sub_domain'] ? 'https://' . $cr['sub_domain'] . '/' : $homeUrl . $cr['classpath'] . '/';
$isLast = ($cr['classid'] == $GLOBALS['navclassid']);
echo $isLast
? '<span class="current" aria-current="page">' . $cr['classname'] . '</span>'
: '<a href="' . $url . '">' . $cr['classname'] . '</a>';
$jsonLd = ['@context' => 'https://schema.org', '@type' => 'BreadcrumbList', 'itemListElement' => []];
$pos = 1;
$jsonLd['itemListElement'][] = ['@type' => 'ListItem', 'position' => $pos++, 'item' => ['@id' => $homeUrl, 'name' => '首頁']];
foreach ($crumbs as $cr) {
$jsonLd['itemListElement'][] = ['@type' => 'ListItem', 'position' => $pos++, 'item' => ['@id' => $homeUrl . $cr['classpath'], 'name' => $cr['classname']]];
}
echo '<script type="application/ld+json">' . json_encode($jsonLd, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) . '</script>';
e/plugins/LinkNav/),避免核心文件衝突,升級無感。e/extend/ 自定義頁面實現「動態導航緩存」,高並發下減少遞歸查詢開銷。測試環境:EmpireCMS 7.5/8.0,PHP 7.4+。代碼採用預處理語句風格防注入,實際部署請配合 intval() 等類型轉換。