首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> 網頁程式設計 >> PHP 程式設計 >> PHP 綜合知識

帝國CMS 常用標籤速查手冊:從會員判斷到 SQL 語句

     編輯:PHP 綜合知識

前言

帝國CMS(EmpireCMS)功能強大,但標籤眾多,開發時常需查閱。本文整理高頻使用的標籤、PHP 片段與 SQL 語句,分類標註,方便二次開發快速查找。

一、會員登入狀態判斷

<?php
if (!isset($_COOKIE['ecmsmlusername'])) {
    $srr = "登入可見";
} else {
    $srr = "[!--lbsly--]"; // 登入後顯示內容
}
?>

二、欄目與頁面通用標籤

1. 當前欄目 SEO 資訊

<title><?=$class_r[$GLOBALS['navclassid']]['bname']?></title>
<meta name="keywords" content="[!--pagekey--]" />
<meta name="description" content="[!--pagedes--]" />

2. 取得頂級欄目 ID 與名稱

<?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']?> // 頂級欄目名 + 網站標題

三、靈動標籤(e:loop)常用寫法

需求標籤範例
指定欄目最新 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']; // 通用寫法

五、常用 SQL 查詢語句(帝國 7.0 需移除 checked=1)

-- 最新文章
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;

六、實用小技巧

1. PHP 三元運算子處理副標題

<?=$bqr['ftitle'] ? $bqr['ftitle'] : $bqr['title']?>

2. 編輯器內容需去反斜線

<?=stripslashes($r['newstext'])?>

3. 判斷內容是否有圖片,無圖則顯示廣告

<?php
$string = $navinfor['newstext'];
$some = "<img ";
$num = explode($some, $string);
if (count($num) > 1) { ?>
    [!--newstext--]
<?php } else { ?>
    <div id="ad">我是廣告</div>
    [!--newstext--]
<?php } ?>

4. 截取並過濾 HTML 標籤

<?=esub(htmlspecialchars(strip_tags($navinfor['newstext'])),160)?>

5. 標題屬性套用(加粗、顏色等)

內容頁:<?=DoTitleFont($navinfor['titlefont'], $navinfor['title'])?>
靈動標籤:<?=DoTitleFont($bqr['titlefont'], $bqr['title'])?>
截取+屬性:<?=DoTitleFont($bqr['titlefont'], esub($bqr['title'],32,'...'))?>

6. 常用變數速查

需求程式碼
內容頁資料 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% 以上的高頻需求,建議收藏備查。若有遺漏或版本差異,歡迎補充交流。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved