帝國CMS(EmpireCMS)功能強大,但標籤眾多,開發時常需查閱。本文整理高頻使用的標籤、PHP 片段與 SQL 語句,分類標註,方便二次開發快速查找。
<?php
if (!isset($_COOKIE['ecmsmlusername'])) {
$srr = "登入可見";
} else {
$srr = "[!--lbsly--]"; // 登入後顯示內容
}
?>
<title><?=$class_r[$GLOBALS['navclassid']]['bname']?></title> <meta name="keywords" content="[!--pagekey--]" /> <meta name="description" content="[!--pagedes--]" />
<?php
$fcr = explode('|', $class_r[$GLOBALS['navclassid']]['featherclass']);
$topbclassid = $fcr[1] ? $fcr[1] : $GLOBALS['navclassid'];
$rs = $empire->fetch1("select * from phome_enewsclass where classid=$topbclassid");
?>
_<?=$rs['bname']?>_<?=$public_r['sitename']?> // 頂級欄目名 + 網站標題
| 需求 | 標籤範例 |
|---|---|
| 指定欄目最新 10 筆 | [e:loop={10,10,0,0}] |
| 推薦文章(isgood=1) | [e:loop={"select * from phome_ecms_news where isgood=1 order by newstime desc limit 10",10,24,0}] |
| 頭條文章(firsttitle=1) | [e:loop={"select * from phome_ecms_news where firsttitle=1 order by newstime desc limit 10",10,24,0}] |
| 按點擊排行 | [e:loop={"select * from phome_ecms_news order by onclick desc limit 10",10,24,0}] |
| 帶圖片條件 | [e:loop={4,1000,0,1,'leib="樓市快訊"','id DESC'}] (第4參數=1 表有圖) |
<?=$bqno?> / [!--no.num--] 循環序號<?=$bqsr['titleurl']?> 文章連結<?=$bqr['title']?> 完整標題<?=esub($bqr['title'],8)?> 截取 8 字<?=date("Y-m-d",$bqr['newstime'])?> 格式化時間<?=format_datetime($bqr['newstime'],'Y-m-d')?> 內建函式(推薦)[!--newsnav--][!--no.num--][!--show.listpage--][!--info.pre--] / [!--info.next--][!--onclick--],靈動標籤 <?=$bqr['onclick']?>$titleurl = sys_ReturnBqTitleLink($navinfor); // 標準寫法 $url = "https://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']; // 通用寫法
-- 最新文章 select * from [!db.pre!]ecms_news where checked=1 order by newstime desc limit 10; -- 推薦文章 select * from [!db.pre!]ecms_news where checked=1 and isgood=1 order by newstime desc limit 10; -- 熱門文章 select * from [!db.pre!]ecms_news where checked=1 order by onclick desc limit 10; -- 頭條新聞 select * from [!db.pre!]ecms_news where checked=1 and firsttitle=1 order by newstime desc limit 10; -- 評論排行 select * from [!db.pre!]ecms_news where checked=1 order by plnum desc limit 10;
<?=$bqr['ftitle'] ? $bqr['ftitle'] : $bqr['title']?>
<?=stripslashes($r['newstext'])?>
<?php
$string = $navinfor['newstext'];
$some = "<img ";
$num = explode($some, $string);
if (count($num) > 1) { ?>
[!--newstext--]
<?php } else { ?>
<div id="ad">我是廣告</div>
[!--newstext--]
<?php } ?>
<?=esub(htmlspecialchars(strip_tags($navinfor['newstext'])),160)?>
內容頁:<?=DoTitleFont($navinfor['titlefont'], $navinfor['title'])?> 靈動標籤:<?=DoTitleFont($bqr['titlefont'], $bqr['title'])?> 截取+屬性:<?=DoTitleFont($bqr['titlefont'], esub($bqr['title'],32,'...'))?>
| 需求 | 程式碼 |
|---|---|
| 內容頁資料 ID | $navinfor['id'] |
| 列表模板資料 ID | $r['id'] |
| 當前欄目名稱 | $class_r[$GLOBALS['navclassid']]['classname'] |
| 父欄目 ID | $class_r[$GLOBALS['navclassid']]['bclassid'] |
| 欄目別名 | $class_r[$GLOBALS['navclassid']]['bname'] |
| 子欄目字串 | $class_r[$GLOBALS['navclassid']]['sonclass'] |
| 是否終極欄目 | $class_r[$GLOBALS['navclassid']]['islast'] |
| 欄目是否有審核通過資料 | $GLOBALS['num']==0 表無資料 |
| 引入 PHP 檔案(根目錄) | <?php include(ECMS_PATH."./bottom.php");?> |
| 排除置頂/推薦/頭條 | 'istop=0 and isgood=0 and firsttitle=0' |
| 上上級欄目 ID | <?php $bclassid=$class_r[$GLOBALS['navclassid']]['bclassid']; $bbclassid=$class_r[$bclassid]['bclassid']; echo $bbclassid;?> |
| 投稿/登入/回饋後跳轉頁面 | <input type=hidden name=ecmsfrom value="返回頁面地址"> |
| 統計收藏數 | <? $favas=$empire->gettotal("select count(*) as total from {$dbtbpre}enewsfava where id='$navinfor[id]' and classid='$GLOBALS[navclassid]'"); ?><?=$favas?> |
| 列表/結合項無資料提示 | <? if($GLOBALS['num']=='0'){ ?><p>暫無資料</p><? }else{ ?>[!--empirenews.listtemp--]<? } ?> |
| 動態調用網站名稱/網址 | <?=$public_r['sitename']?> / <?=$public_r['newsurl']?> |
本手冊涵蓋帝國CMS 二次開發 90% 以上的高頻需求,建議收藏備查。若有遺漏或版本差異,歡迎補充交流。