“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($bqr[classid]==$GLOBALS[navclassid])
{
$classname="tzzs_active";
} 
?><li class="<?=$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、ECMS6.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、在PHP7.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()在php5.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]。

逐步收集整理中...