在日常建站过程中,整理了一些帝国ECMS常用技巧集

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=&quot;tzzs_active&quot;;
} 
?&gt;&lt;li class=&quot;&lt;?=$classname?&gt;&quot;&gt;&lt;a href=&quot;&lt;?=$classurl?&gt;&quot;&gt;&lt;?=$bqr[classname]?&gt;&lt;/a&gt;&lt;/li&gt;[/e:loop]</code></pre><p>其中“classid&lt;&gt;25”为排除指定栏目<br>增加代码可不调用隐藏设置的栏目:<code>and showclass=0</code> //0为显示,1为不显示<br>若在列表模板里,需要判断当前栏目的父栏目id,直接使用<code>bclassid=[!--bclass.id--]</code>是无效的。<br>需要在页面顶部先获取父栏目的id数字才有效,代码如下:</p><pre><code class="lang-php">&lt;?php
    $a=$GLOBALS[navclassid];
    $b= $class_r[$a][&#039;bclassid&#039;];
?&gt;</code></pre><p>同时,灵动标签内<code>bclassid=$b</code>来实现父栏目id的调用,该方法同时适用内容模板页面。</p><h3>2、复选项输出值的调用</h3><p>(讨论<a href="http://bbs.phome.net/ShowThread/?threadid=360510&forumid=42" rel="nofollow">http://bbs.phome.net/ShowThread/?threadid=360510&forumid=42</a>)</p><pre><code class="lang-PHP">&lt;?php
$shyashuasx=$navinfor[yashuasx];
$shyashuasx=rtrim($shyashuasx, &quot;|&quot;);
$shyashuasx=ltrim($shyashuasx, &quot;|&quot;);
$shyasarry = explode(&#039;|&#039;,$shyashuasx); 
for($index=0;$index&lt;count($shyasarry);$index++) 
{ 
?&gt;
  &lt;div class=&quot;fl feature&quot;&gt;
    &lt;img src=&quot;[!--news.url--]skin/images/i/&lt;?=$shyasarry[$index]?&gt;.png&quot; alt=&quot;&lt;?=$shyasarry[$index]?&gt;&quot;&gt;
    &lt;br&gt;
    &lt;?=$shyasarry[$index]?&gt;
  &lt;/div&gt;
&lt;?php
} 
?&gt; </code></pre><h3>3、列表内容模板,需要判断是否登录调用不同的内容</h3><p>(讨论<a href="http://bbs.phome.net/ShowThread/?threadid=360336&forumid=42" rel="nofollow">http://bbs.phome.net/ShowThread/?threadid=360336&forumid=42</a>)<br>页面模板内容部分:</p><pre><code class="lang-PHP">&lt;?php
include(&quot;e/class/connect.php&quot;);  
$lguserid=intval(getcvar(&#039;mluserid&#039;));//登陆用户ID
$lgusername=RepPostVar(getcvar(&#039;mlusername&#039;));//登陆用户
$lggroupid=intval(getcvar(&#039;mlgroupid&#039;));//会员组ID

if($lggroupid){
?&gt;
    &lt;div class=&quot;zinfo&quot;&gt;“[!--class.name--]”共&lt;em&gt;[totaldata]$GLOBALS[navclassid],0,0[/totaldata]&lt;/em&gt;条信息。欢迎&lt;em&gt;&lt;?php echo $lgusername;?&gt;&lt;/em&gt;,用完记得&lt;a href=&quot;/e/member/doaction.php?enews=exit&quot;&gt;[退出]&lt;/a&gt;&lt;/div&gt;
&lt;?php
}else{
?&gt;
    &lt;div class=&quot;zinfo&quot;&gt;“[!--class.name--]”共&lt;em&gt;[totaldata]$GLOBALS[navclassid],0,0[/totaldata]&lt;/em&gt;条信息。列表仅显示条数,请&lt;a href=&quot;/e/member/login/&quot; target=&quot;_blank&quot;&gt;登录&lt;/a&gt;刷新页面后,查看详细信息。&lt;/div&gt;
&lt;?php
}
?&gt;</code></pre><p>列表内容模板部分(使用程序代码)</p><pre><code class="lang-PHP">include(&quot;e/class/connect.php&quot;);  
$lguserid=intval(getcvar(&#039;mluserid&#039;));//登陆用户ID
$lgusername=RepPostVar(getcvar(&#039;mlusername&#039;));//登陆用户
$lggroupid=intval(getcvar(&#039;mlgroupid&#039;));//会员组ID

if($lggroupid){
$listtemp=&#039;&lt;li&gt;&lt;a href=&quot;[!--titleurl--]&quot;&gt;&lt;img src=&quot;[!--titlepic--]&quot; alt=&quot;[!--oldtitle--]&quot; /&gt;&lt;span&gt;[!--title--]&lt;span&gt;&lt;/a&gt;&lt;/li&gt;&#039;;
}else{
$listtemp=&#039;&lt;li&gt;&lt;img src=&quot;/skin/images/p.png&quot; alt=&quot;代用名&quot; /&gt;&lt;span&gt;[&lt;a href=&quot;/e/member/login/&quot; target=&quot;_blank&quot;&gt;登录后显示&lt;/a&gt;]&lt;/span&gt;&lt;/li&gt;&#039;;
}</code></pre><h3>4、结合项的信息数据统计</h3><p>(讨论<a href="http://bbs.phome.net/showthread-42-360251-0.html" rel="nofollow">http://bbs.phome.net/showthread-42-360251-0.html</a>)<br>模板变量:</p><pre><code class="lang-PHP">&lt;?php 
$my_string=$class_r[$GLOBALS[navclassid]][&#039;sonclass&#039;];
$my_string=ltrim(rtrim($my_string, &quot;|&quot;), &quot;|&quot;); 
$my_string=str_replace(&quot;|&quot;,&quot;,&quot;,$my_string);
?&gt;
&lt;li class=&quot;t1&quot;&gt;团员,共&lt;em&gt;&lt;?php $num=$empire-&gt;gettotal(&quot;select count(*) as total from phome_ecms_news where classid in($my_string) and shuxing=&#039;团员&#039;&quot;);echo $num;?&gt;&lt;/em&gt;人;&lt;/li&gt;</code></pre><h3>5、灵动标签统计后台用户发布信息数量(同时排除不需要参与统计的用户)</h3><pre><code class="lang-PHP">[e:loop={&quot;select id,username,count(*) as total from phome_ecms_news WHERE username&lt;&gt;&#039;aijun&#039; and username&lt;&gt;&#039;admin&#039; GROUP BY username ORDER BY total DESC LIMIT 0,10&quot;,0,24,0}]
&lt;li&gt;&lt;span&gt;&lt;?=$bqr[total]?&gt;&lt;/span&gt; &lt;em&gt;&lt;?=$bqno?&gt;&lt;/em&gt; &lt;?=$bqr[username]?&gt;&lt;/li&gt;
[/e:loop]</code></pre><h3>6、标签模板使用程序代码,将时间分开调用(YY-MM-DD)</h3><pre><code class="lang-PHP">$y_time=date(&#039;Y&#039;,$r[newstime]);
$m_time=date(&#039;m&#039;,$r[newstime]);
$d_time=date(&#039;d&#039;,$r[newstime]);
$listtemp=&#039;&lt;li&gt;&lt;div class=&quot;ny_time&quot;&gt;&lt;em&gt;&#039;.$m_time.&#039;-&#039;.$d_time.&#039;&lt;/em&gt;&lt;br /&gt;&#039;.$y_time.&#039;&lt;/div&gt;&lt;/li&gt;&#039;;</code></pre><h3>7、ECMS6.0版以后的验证码地址有所变化</h3><p>评论验证码:/e/ShowKey/?v=pl<br>登陆验证码:/e/ShowKey/?v=login<br>注册验证码:/e/ShowKey/?v=reg<br>投稿验证码:/e/ShowKey/?v=info<br>留言板验证码:/e/ShowKey/?v=gbook<br>信息反馈验证码:/e/ShowKey/?v=feedback<br>取回密码验证码:/e/ShowKey/?v=getpassword<br>会员空间反馈验证码:/e/ShowKey/?v=spacefb<br>会员空间留言验证码:/e/ShowKey/?v=spacegb<br>验证码调用(可点击刷新):<br><code>&lt;img src=&#039;/e/ShowKey/?v=feedback&#039; onclick=&#039;this.src=&quot;/e/ShowKey/?v=feedback&amp;&quot;+Math.random();&#039; style=&#039;cursor:pointer;height:37px;&#039;&gt;</code><br>后台登录,点击显示验证码:<br><code>&lt;div id=&quot;checkkeyshowkey&quot;&gt;&lt;a href=&quot;#EmpireCMS&quot; onclick=&quot;edoshowkey(&#039;checkkeyshowkey&#039;,&#039;checkkey&#039;);&quot; title=&quot;点击显示验证码&quot;&gt;点击显示&lt;/a&gt;&lt;/div&gt;</code></p><h3>8、[!--pagedes--]在内容页调用默认调用标题的无损解法:</h3><p>通常大家可能会去修改functions.php,对以后升级会存在影响,为了SEO想了一个折中简单的办法。<br><code>&lt;meta name=&quot;description&quot; content=&quot;&lt;?=$navinfor[id]?$navinfor[smalltext].&#039;---&#039;:&#039;&#039;?&gt;[!--pagedes--]&quot; /&gt;</code></p><h3>9、其他一些零散细节代码</h3><p>⑴ 获取栏目网址:<br><code>$classurl=sys_ReturnBqClassname($bqr,9);//取得栏目地址</code><br>⑵ 判断是否首页(用于高亮):<br><code>&lt;?=(!$GLOBALS[navclassid])?&#039; class=&quot;cur&quot;&#039;:&#039;&#039;?&gt;</code><br>⑶ 判断是否当前页(高亮):<br><code>&lt;?=($GLOBALS[navclassid]$bqr[classid])?' class="cur"':''?>
⑷ 按照指定排序调用SQL语句片段(配合条件调用):
order by field(classid,10,3,4,41,40)
⑸ 栏目导航中判断某栏目是否为终极栏目:
if ($bqr[sonclass]&#039;&#039; 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]。

逐步收集整理中...

发表评论

行为验证™ 安全组件加载中...

评论 1 条

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

    写的很好,支持一下

文章目录