帝国CMS灵动标签e:loop的使用 格式:
[e:loop={栏目ID/专题ID,显示条数,操作类型,只显示有标题图片,附加SQL条件,显示排序}] 模板代码内容 [/e:loop] 例子:
< table width ="100%" border ="0" cellspacing ="1" cellpadding ="3" > [e:loop={栏目ID/专题ID,显示条数,操作类型,只显示有标题图片,附加SQL条件,显示排序}] < tr >< td > < a href ="<?=$bqsr[titleurl]?>" target ="_blank" > <? =$bqr[title] ?> </ a > ( <? =date('Y-m-d',$bqr[newstime]) ?> ) </ td ></ tr > [/e:loop] </ table >
标签说明:灵动标签是无需做标签模板,且模板内容为PHP代码,因而更灵活,可以使用php所有处理函数。使用本标签,需开启模板支持程序代码(参数设置)。
参数:
栏目ID/专题ID:查看栏目ID点这里,查看专题ID点这里,当前ID='selfinfo',多个栏目ID与专题ID可用,号格开,如'1,2'。 显示条数:显示前几条记录。 操作类型:具体看操作类型说明。 只显示有标题图片:0为不限制,1为只显示有标题图片的信息。 附加SQL条件:附加调用条件,如:"title='帝国'"。 显示排序:可指定按相应的字段排序,如:"id desc"。 变量说明:
$bqr:$bqr[字段名]:显示字段的内容 $bqsr:$bqsr[titleurl]:标题链接,$bqsr[classname]:栏目名称,$bqsr[classurl]:栏目链接 $bqno:$bqno:为调用序号 $public_r:$public_r[newsurl]:网站地址 常用函数介绍:
文字截取:esub(字符串,截取长度),例子:esub($bqr[title],30)截取标题前30个字符。
时间格式:date('格式字串',时间字段),例子:date('Y-m-d',$bqr[newstime])时间显示格式为"2008-10-01"。
实例1:如果信息为当天就加New标志
本功能实现调用信息时候如果是当天发布的最新信息显示New标志图片。
< ul > [e:loop={栏目ID,显示条数,操作类型,只显示有标题图片}] <? $newimg=""; if(date("m-d",$bqr[truetime]) == date("m-d")) { $newimg = "<img src='New图片地址'>"; } ?> < li > < a href ="<?=$bqsr[titleurl]?>" target ="_blank" > <? =sub($bqr[title],0,10,false) ?> </ a > <? =$newimg ?> </ li > [/e:loop] </ ul >
说明:首先定义newimg为空如果日期=当天则显示New图片,用<?=$newimg?>在您想要的适当位置调用。
实例2:在灵动标签内使用SQL
[e:loop={'select * from phome_ecms_news where classid=72 order by id DESC limit 6',6,24,0}] 注意倒数第二个参数为24,才可以使用SQL。
[e:loop={'select * from [!db.pre!]ecms_news where classid=72 and type='开发商' order by id DESC limit 6',6,24,0}] < li class ="class1" > < a href ='http://www.hkqipilang.acafa.com/' target =_blank title ='<?=$bqr[title]?>' > <? =$bqr[title] ?> </ a > < div class ="top_div_myAcafa_u" > <? =$bqr[address] ?> < br /> 业务范围: <? =$bqr[smalltext] ?> </ div > </ li > [/e:loop] 实例3:如果信息带有图片信息,则标题上带有图片标志
[e:loop={'selfinfo',20,0,0}] <? $newimg=""; if(!empty($bqr[titlepic])) { $newimg="<img src='http://bbs.zhnews.net/bbs/static/image/filetype/image_s.gif' />"; } ?> <tr class="even"> <td class="title"> <h1><a href="<?=$bqsr[titleurl]?>" target="_blank"><?=sub($bqr[title],0,24,false)?></a> <?=$newimg?></h1> <p class="intro"> <?=$bqr[smalltext]?>[<a title="阅读全文" href="<?=$bqsr[titleurl]?>" target="_blank">详细内容</a> ] </p> </td> <td><?=$bqr[myarea]?></td> <td><?=date('Y-m-d H:i:s', $bqr[newstime])?></td> </tr>
[/e:loop]
显示字段用<?=$bqr[字段]?>,$bqsr就几个变量:
$bqsr[titleurl]:标题链接 $bqsr[classname]:栏目名称 $bqsr[classurl]:栏目链接 $bqsr[titleurl]:标题链接 $bqsr[classname]:栏目名称 $bqsr[classurl]:栏目链接 除了这几个其他的都用$bqr。 实例1:
<!-- 最新300条中点击率最高的2条 -->
[e:loop={'select * from (select a.id,a.title,a.newspath,a.newstime,b.classpath,b.classname,b.filetype,a.onclick,a.smalltext from '.$dbtbpre.'ecms_article as a,'.$dbtbpre.'enewsclass b where a.classid=b.classid and a.checked=1 order by a.newstime desc limit 200) as new300 order by new300.onclick desc limit 2',1,24,0}] < li > < a href ="[!--news.url--]<?=$bqr[classpath].'/'.$bqr[newspath].'/'.$bqr[id].$bqr[filetype ]?>" target ="_blank" title ="<?=$bqr[title]?>" >< h3 > <? =sub($bqr[title],0,30,false) ?> </ h3 ></ a > < spn > <? =sub($bqr[smalltext],0,150,false) ?> …… </ span > </ li > [/e:loop] 实例2:
[e:loop={'article',4,20,1}] < div id ="body_left_Panel_Components1_body_No1" class ="body_left_Panel_Components1_body_No1" > < div id ="body_left_Panel_Components1_body_No1_img" class ="body_left_Panel_Components1_body_No1_img" > < a title ="<?=$bqr[title]?>" href ="<?=$bqsr[titleurl]?>" > < img height ="62" width ="115" alt ="<?=$bqr[title]?>" src ="<?=$bqr[titlepic]?>" /> </ a > </ div > < div id ="body_left_Panel_Components1_body_No1_text" class ="body_left_Panel_Components1_body_No1_text" > < ul > <!-- 提高Adsense相关度抓取 --> <!-- google_ad_section_start --> <? php $newimg=""; $sql_good=$empire->query("select * from (select a.id,a.title,a.newspath,a.newstime,b.classpath,b.classname,b.filetype from ".$dbtbpre."ecms_article as a,".$dbtbpre."enewsclass b where a.classid=b.classid and a.checked=1 and a.isgood=1 order by a.onclick desc limit 12) as a1 order by length(a1.title) limit ".($good_pageSize*$good_limitsize).",".$good_limitsize); $_i=$good_limitsize*$good_pageSize+1; while($info=$empire->fetch($sql_good)) { ?> < li > < img src ="[!--news.url--]face/image/<?=$_i?>.gif" alt ="<?=$info[title]?>" width ="11" height ="9" />< a href ="[!--news.url--]<?=$info[classpath].'/'.$info[newspath].'/'.$info[id].$info[filetype ]?>" target ="_blank" title ="<?=$info[title]?>" > <? =sub($info[title],0,20,false) ?> </ a > </ li > <? php $_i++; } $good_pageSize++; ?> <!-- google_ad_section_end --> </ ul > </ div > </ div > [/e:loop] 实例3:
[e:loop={'select classid,classpath,classname from [!db.pre!]enewsclass where classid in ("47","48","49","50","51","52","53","54","55","103","112") order by classid',1,24,0}] < div id ="body_left_Pane2" class ="body_left_Pane2" > < div id ="body_left_Pane2_title" class ="body_left_Pane2_title" > < span >< h4 >< a href ="[!--news.url--]<?=$bqr[classpath]?>/" title ="<?=$bqr[classname]?>" > <? =$bqr[classname] ?> </ a ></ h4 ></ span > < span ></ span >< span ></ span > <? php $newimg=""; $sql=$empire->query("select classid,classpath,classname from ".$dbtbpre."enewsclass where bclassid=$bqr[classid] order by classid"); while($info=$empire->fetch($sql)) { ?> < span >< a href ="[!--news.url--]<?=$info[classpath]?>/" title ="<?=$info[classname]?>" > <? =$info[classname] ?> </ a ></ span > <? php } ?> </ div > < div id ="body_left_Pane2_body" class ="body_left_Pane2_body" > < div id ="body_left_Pane2_body_left" class ="body_left_Pane2_body_left" >
< div id ="body_left_Pane2_body_left_title" class ="body_left_Pane2_body_left_title" > <? php $newimg=""; $sql=$empire->query("select a.*,b.filetype,b.classpath,b.classname from ".$dbtbpre."ecms_article as a,".$dbtbpre."enewsclass b where a.classid=b.classid and a.checked=1 and a.firsttitle=1 and length(a.titlepic)>3 and a.classid in (select classid from ".$dbtbpre."enewsclass where bclassid=$bqr[classid]) order by a.newstime desc limit 1"); while($info=$empire->fetch($sql)) { ?> < div id ="body_left_Pane2_body_left_title_pic" class ="body_left_Pane2_body_left_title_pic" > < img src ="<?=$info[titlepic]?>" title ="<?=$info[title]?>" width ="80" height ="60" /> </ div > < div id ="body_left_Pane2_body_left_title_right" class ="body_left_Pane2_body_left_title_right" > < h5 >< a href ="[!--news.url--]<?=$info[classpath].'/'.$info[newspath].'/'.$info[id].$info[filetype ]?>" target ="_blank" title ="<?$info[title]?>" > <? =sub($info[title],0,20,false) ?> </ a ></ h5 > <? =sub($info[smalltext],0,100,false) ?> …… </ div > <? php } ?> </ div >
< div id ="body_left_Pane2_body_left_body" class ="body_left_Pane2_body_left_body" > < ul > <? php $newimg=""; $sql=$empire->query("select a.id,a.title,a.newspath,a.newstime,b.classpath,b.classname,b.filetype from ".$dbtbpre."ecms_article as a,".$dbtbpre."enewsclass b where a.classid=b.classid and a.checked=1 and a.classid in (select classid from ".$dbtbpre."enewsclass where bclassid='$bqr[classid]' order by classid) order by a.onclick desc,a.newstime desc limit ".$limitsize); while($info=$empire->fetch($sql)) { if (date("y-m-d",$info[newstime])==date("y-m-d")) {$newimg="<font color=red>".date("m-d",$info[newstime])."</font>";} else {$newimg=date("m-d",$info[newstime]);} ?> < li > < a href ="[!--news.url--]<?=$info[classpath].'/'.$info[newspath].'/'.$info[id].$info[filetype ]?>" target ="_blank" title ="<?=$info[title]?>" > <? =sub($info[title],0,30,false) ?> </ a > </ li > <? php } ?> </ ul > </ div > </ div > < div id ="body_left_Pane2_body_right" class ="body_left_Pane2_body_right" > < ul > <? php $newimg=""; $sql=$empire->query("select a.id,a.title,a.newspath,a.newstime,b.classpath,b.classname,b.filetype,b.classid as b_id from ".$dbtbpre."ecms_article as a,".$dbtbpre."enewsclass b where a.classid=b.classid and a.checked=1 and a.classid in (select classid from ".$dbtbpre."enewsclass where bclassid='$bqr[classid]' order by classid) order by a.newstime desc limit ".$limitNewSize); while($info=$empire->fetch($sql)) { if (get_date(date("y-m-d"),date("y-m-d",$info[newstime]))<1) {$newimg="<img src='[!--news.url--]face/image/new.gif' width='25' height='13' title='".date("y-m-d",$info[newstime])."'/>";} else {$newimg="";} ?> < li > < a href ="[!--news.url--]<?=$info[classpath]?>/" title ="<?=$info[classname]?>" > [ <? =$info[classname] ?> ] </ a >< a href ="[!--news.url--]<?=$info[classpath].'/'.$info[newspath].'/'.$info[id].$info[filetype ]?>" target ="_blank" title ="<?=$info[title]?> 日期:<?=date(" Y-m-d",$info[newstime])? > "> <? =sub($info[title],0,18,false) ?> </ a > <? =$newimg ?> </ li > <? php } ?> </ ul > </ div > </ div > </ div > [/e:loop] 下载地址: 帝国cms判断某个字段必须是会员或者VIP会员才能查看的方法 东坡插件之帝国CMS多端同步生成删除插件详细使用教程/适用帝国cms7.2/7.5 |