
1. Looping categories with the flexible tag, with a class for the current one
[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]Here classid<>25 excludes one specific category.
To also skip categories hidden in the admin panel, add and showclass=0 — 0 shows, 1 hides.
Inside a list template, testing the parent category ID of the current category with bclassid=[!--bclass.id--] doesn't work. You have to grab the numeric parent ID at the top of the page first:
<?php
$a=$GLOBALS[navclassid];
$b= $class_r[$a]['bclassid'];
?>Then use bclassid=$b inside the flexible tag. The same approach works on content template pages.
2. Outputting the values of a multi-select field
(Discussion: 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. Showing different list content depending on whether the user is logged in
(Discussion: http://bbs.phome.net/ShowThread/?threadid=360336&forumid=42)
Page template part:
<?php
include("e/class/connect.php");
$lguserid=intval(getcvar('mluserid'));// logged-in user ID
$lgusername=RepPostVar(getcvar('mlusername'));// logged-in username
$lggroupid=intval(getcvar('mlgroupid'));// member group ID
if($lggroupid){
?>
<div class="zinfo">"[!--class.name--]" has <em>[totaldata]$GLOBALS[navclassid],0,0[/totaldata]</em> items. Welcome, <em><?php echo $lgusername;?></em> — remember to <a href="/e/member/doaction.php?enews=exit">[log out]</a> when you're done.</div>
<?php
}else{
?>
<div class="zinfo">"[!--class.name--]" has <em>[totaldata]$GLOBALS[navclassid],0,0[/totaldata]</em> items. Only the count is shown here — please <a href="/e/member/login/" target="_blank">log in</a> and reload the page to see the details.</div>
<?php
}
?>List item template part (using program code)
include("e/class/connect.php");
$lguserid=intval(getcvar('mluserid'));// logged-in user ID
$lgusername=RepPostVar(getcvar('mlusername'));// logged-in username
$lggroupid=intval(getcvar('mlgroupid'));// member group 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="placeholder" /><span>[<a href="/e/member/login/" target="_blank">log in to view</a>]</span></li>';
}4. Counting records that match a set of categories
(Discussion: http://bbs.phome.net/showthread-42-360251-0.html)
Template variable:
<?php
$my_string=$class_r[$GLOBALS[navclassid]]['sonclass'];
$my_string=ltrim(rtrim($my_string, "|"), "|");
$my_string=str_replace("|",",",$my_string);
?>
<li class="t1">Members: <em><?php $num=$empire->gettotal("select count(*) as total from phome_ecms_news where classid in($my_string) and shuxing='Member'");echo $num;?></em> in total;</li>5. Counting posts per back-end user with the flexible tag (skipping the accounts you don't want counted)
[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. Splitting the date into separate parts in a tag template (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. CAPTCHA URLs changed in ECMS 6.0 and later
Comment CAPTCHA: /e/ShowKey/?v=pl
Login CAPTCHA: /e/ShowKey/?v=login
Registration CAPTCHA: /e/ShowKey/?v=reg
Submission CAPTCHA: /e/ShowKey/?v=info
Guestbook CAPTCHA: /e/ShowKey/?v=gbook
Feedback CAPTCHA: /e/ShowKey/?v=feedback
Password recovery CAPTCHA: /e/ShowKey/?v=getpassword
Member space feedback CAPTCHA: /e/ShowKey/?v=spacefb
Member space guestbook CAPTCHA: /e/ShowKey/?v=spacegb
Calling the CAPTCHA (click to refresh):<img src='/e/ShowKey/?v=feedback' onclick='this.src="/e/ShowKey/?v=feedback&"+Math.random();' style='cursor:pointer;height:37px;'>
Admin login, click to reveal the CAPTCHA:<div id="checkkeyshowkey"><a href="#EmpireCMS" onclick="edoshowkey('checkkeyshowkey','checkkey');" title="Click to show the CAPTCHA">Click to show</a></div>
8. A non-destructive fix for [!--pagedes--] defaulting to the title on content pages
Most people would just patch functions.php, which makes future upgrades harder. For SEO purposes I worked out a simple middle ground.<meta name="description" content="<?=$navinfor[id]?$navinfor[smalltext].'---':''?>[!--pagedes--]" />
9. A few loose ends worth keeping
(1) Get a category URL:$classurl=sys_ReturnBqClassname($bqr,9);// get the category URL
(2) Test for the home page (for highlighting):<?=(!$GLOBALS[navclassid])?' class="cur"':''?>
(3) Test for the current page (highlighting):<?=($GLOBALS[navclassid]==$bqr[classid])?' class="cur"':''?>
(4) Call rows in a specific order (combined with other conditions):order by field(classid,10,3,4,41,40)
(5) Test whether a category in the navigation is a leaf:if ($bqr[sonclass]=='' or $bqr[sonclass]=="|")
10. Installing and running on PHP 7.4
(1) File: e/config/config.php$ecms_config['db']['usedb']='mysql';
change to$ecms_config['db']['usedb']='mysqli';
(2) File: e/class/connect.phpdefine('MAGIC_QUOTES_GPC',function_exists('get_magic_quotes_gpc')&&get_magic_quotes_gpc());
change to:define('MAGIC_QUOTES_GPC',(ini_get('magic_quotes_gpc') == 1) ? true : false);
Note: get_magic_quotes_gpc() was removed after PHP 5.4.
11. Two ways to pull a category's alias in Empire CMS
First: inside the terminal category
<?=$class_r[$GLOBALS[navclassid]][bname]?>Second: the universal one, good anywhere, since it hits the database directly.
<?php
$cr=$empire->fetch1("select bname from phome_enewsclass where
classid='".$GLOBALS[navclassid]."' limit 1");
echo $cr['bname'];
?>12. Highlighting the home-page nav item only when on the home page
<?php if(empty($GLOBALS[navclassid])){echo ' class="active"';}?>
Note: this also matches tag pages and custom pages. If you don't want those highlighted too, define a $GLOBALS[navclassid] on the tag and custom pages.
Still adding to this list...
写的很好,支持一下