日常建站整理的一些帝國CMS 常用技巧集

ECMS 技巧

1、靈動標籤呼叫欄目,可定義目前欄目的 class 樣式

[e:loop={"select classid,classname from {$dbtbpre}enewsclass where bclassid=5 and classid<>25 order by myorder,classid asc",0,24,0}]<?php
$classurl = sys_ReturnBqClassname($bqr,9);
$classname = '';
if( (int)$bqr['classid'] === (int)$GLOBALS['navclassid'] )
{
    $classname = ' class="cur"';
}
?><li<?= $classname ?>><a href="<?=$classurl?>"><?=$bqr['classname']?></a></li>[/e:loop]

其中「classid<>25」是排除指定欄目
加上程式碼可排除後台設為隱藏的欄目:and showclass=0 //0 為顯示,1 為不顯示
若在列表範本裡,想判斷目前欄目的父欄目 id,直接用 bclassid=[!--bclass.id--] 是無效的。
必須先於頁面頂端取得父欄目的 id 數字才有效,程式碼如下:

<?php
    $a=$GLOBALS[navclassid];
    $b= $class_r[$a]['bclassid'];
?>

同時在靈動標籤內用 bclassid=$b 來呼叫父欄目 id,這個方法同樣適用內容範本頁面。

2、複選項輸出值的呼叫

(討論:http://bbs.phome.net/ShowThread/?threadid=360510&forumid=42)

<?php
$shyashuasx=$navinfor[yashuasx];
$shyashuasx=rtrim($shyashuasx, "|");
$shyashuasx=ltrim($shyashuasx, "|");
$shyasarry = explode('|',$shyashuasx); 
for($index=0;$index<count($shyasarry);$index++) 
{ 
?>
  <div class="fl feature">
    <img src="[!--news.url--]skin/images/i/<?=$shyasarry[$index]?>.png" alt="<?=$shyasarry[$index]?>">
    <br>
    <?=$shyasarry[$index]?>
  </div>
<?php
} 
?> 

3、列表內容範本依登入狀態呼叫不同內容

(討論:http://bbs.phome.net/ShowThread/?threadid=360336&forumid=42)
頁面範本內容部分:

<?php
include("e/class/connect.php");  
$lguserid=intval(getcvar('mluserid'));//登入使用者 ID
$lgusername=RepPostVar(getcvar('mlusername'));//登入使用者
$lggroupid=intval(getcvar('mlgroupid'));//會員組 ID

if($lggroupid){
?>
    <div class="zinfo">「[!--class.name--]」共 <em>[totaldata]$GLOBALS[navclassid],0,0[/totaldata]</em> 則資訊。歡迎 <em><?php echo $lgusername;?></em>,用完記得<a href="/e/member/doaction.php?enews=exit">[登出]</a></div>
<?php
}else{
?>
    <div class="zinfo">「[!--class.name--]」共 <em>[totaldata]$GLOBALS[navclassid],0,0[/totaldata]</em> 則資訊。列表僅顯示則數,請<a href="/e/member/login/" target="_blank">登入</a>並重新整理頁面後,檢視詳細資訊。</div>
<?php
}
?>

列表內容範本部分(使用程式碼)

include("e/class/connect.php");  
$lguserid=intval(getcvar('mluserid'));//登入使用者 ID
$lgusername=RepPostVar(getcvar('mlusername'));//登入使用者
$lggroupid=intval(getcvar('mlgroupid'));//會員組 ID

if($lggroupid){
$listtemp='<li><a href="[!--titleurl--]"><img src="[!--titlepic--]" alt="[!--oldtitle--]" /><span>[!--title--]<span></a></li>';
}else{
$listtemp='<li><img src="/skin/images/p.png" alt="示意圖" /><span>[<a href="/e/member/login/" target="_blank">登入後顯示</a>]</span></li>';
}

4、結合項目的資訊數據統計

(討論:http://bbs.phome.net/showthread-42-360251-0.html)
範本變數:

<?php 
$my_string=$class_r[$GLOBALS[navclassid]]['sonclass'];
$my_string=ltrim(rtrim($my_string, "|"), "|"); 
$my_string=str_replace("|",",",$my_string);
?>
<li class="t1">團員,共 <em><?php $num=$empire->gettotal("select count(*) as total from phome_ecms_news where classid in($my_string) and shuxing='團員'");echo $num;?></em> 人;</li>

5、靈動標籤統計後台使用者發布資訊數量(同時排除不需計入統計的使用者)

[e:loop={"select id,username,count(*) as total from phome_ecms_news WHERE username<>'aijun' and username<>'admin' GROUP BY username ORDER BY total DESC LIMIT 0,10",0,24,0}]
<li><span><?=$bqr[total]?></span> <em><?=$bqno?></em> <?=$bqr[username]?></li>
[/e:loop]

6、標籤範本使用程式碼,將時間分開呼叫(YY-MM-DD)

$y_time=date('Y',$r[newstime]);
$m_time=date('m',$r[newstime]);
$d_time=date('d',$r[newstime]);
$listtemp='<li><div class="ny_time"><em>'.$m_time.'-'.$d_time.'</em><br />'.$y_time.'</div></li>';

7、ECMS 6.0 版以後驗證碼位址有變動

評論驗證碼:/e/ShowKey/?v=pl
登入驗證碼:/e/ShowKey/?v=login
註冊驗證碼:/e/ShowKey/?v=reg
投稿驗證碼:/e/ShowKey/?v=info
留言板驗證碼:/e/ShowKey/?v=gbook
資訊回饋驗證碼:/e/ShowKey/?v=feedback
取回密碼驗證碼:/e/ShowKey/?v=getpassword
會員空間回饋驗證碼:/e/ShowKey/?v=spacefb
會員空間留言驗證碼:/e/ShowKey/?v=spacegb

驗證碼呼叫(可點擊重新整理):
<img src='/e/ShowKey/?v=feedback' onclick='this.src="/e/ShowKey/?v=feedback&"+Math.random();' style='cursor:pointer;height:37px;'>
後台登入,點擊顯示驗證碼:
<div id="checkkeyshowkey"><a href="#EmpireCMS" onclick="edoshowkey('checkkeyshowkey','checkkey');" title="點擊顯示驗證碼">點擊顯示</a></div>

8、[!--pagedes--] 在內容頁預設呼叫標題,不破壞原功能的解法

一般大家可能會去改 functions.php,但這樣會影響日後升級。為了 SEO,想了一個折中又簡單的辦法。
<meta name="description" content="<?=$navinfor[id]?$navinfor[smalltext].'---':''?>[!--pagedes--]" />

9、其他一些零散的細節程式碼

⑴ 取得欄目網址:
$classurl=sys_ReturnBqClassname($bqr,9);//取得欄目位址
⑵ 判斷是否首頁(用於高亮):
<?=(!$GLOBALS[navclassid])?' class="cur"':''?>
⑶ 判斷是否目前頁面(高亮):
<?=($GLOBALS[navclassid]==$bqr[classid])?' class="cur"':''?>
⑷ 依指定順序呼叫 SQL 語句片段(搭配條件呼叫):
order by field(classid,10,3,4,41,40)
⑸ 欄目導覽中判斷某欄目是否為終極欄目:
if ($bqr[sonclass]=='' or $bqr[sonclass]=="|")

10、在 PHP 7.4 上安裝/執行的注意事項

⑴ 檔案:e/config/config.php
$ecms_config['db']['usedb']='mysql';
改為
$ecms_config['db']['usedb']='mysqli';

⑵ 檔案:e/class/connect.php
define('MAGIC_QUOTES_GPC',function_exists('get_magic_quotes_gpc')&&get_magic_quotes_gpc());
改為:
define('MAGIC_QUOTES_GPC',(ini_get('magic_quotes_gpc') == 1) ? true : false);

說明:get_magic_quotes_gpc() 在 PHP 5.4 版之後已廢除。

11、帝國CMS 呼叫欄目別名的兩種方法

第一種:在最終欄目呼叫

<?=$class_r[$GLOBALS[navclassid]][bname]?>

第二種:萬用型,哪裡都行,因為是直接查資料庫輸出的!

<?php 
$cr=$empire->fetch1("select bname from phome_enewsclass where 
classid='".$GLOBALS[navclassid]."' limit 1"); 
echo $cr['bname']; 
?>

12、判斷目前頁面為首頁,首頁是否高亮顯示

<?php if(empty($GLOBALS[navclassid])){echo ' class="active"';}?>
說明:這個判斷會同時匹配首頁、TAG 頁面和自訂頁面,若不想 TAG 頁面和自訂頁面也被高亮,可以在 TAG 頁面和自訂頁面另外定義一個 $GLOBALS[navclassid]。

逐步收集整理中...

發表評論

評論 1 則

  • 丘八
    丘八 2019-07-06 10:36 回覆

    写的很好,支持一下

文章目錄