导航
当前位置:网站首页 > 站长新闻 > CMS教程 > 织梦模板中使用php和if判断语句的技巧

织梦模板中使用php和if判断语句的技巧

作者:king 日期:2023-05-17 分类:CMS教程

1 {dede:field.zufang_tel php=yes}
2 if(@me==""||empty(@me))
3 @me="<p>无</p>";
4 {/dede:field.zufang_tel}
注释:
@me:就是当前字段的值,你可以在if中给其赋值,然后判断结束后它的值就变成你赋的值,打印出来
具体方法如下:
方法一:
用个if判断语句,判断一个字段是否有东西,有责输出1,没有则输出2,
下面是的代码加载内容页模板中
{dede:field.audio runphp='yes'}
if(@me<>'')@me="如果audio字段里有东西就输出这个,支持html代码,并且可以在代码中使用@me来调用audio字段值,但是不要有双引号。";
else
@me="如果audio字段里没有东西就输出这个,也是支持html代码,并且也是可以在代码中使用@me来调用audio字段值,也是不要有双引号。";
{/dede:field.audio}
audio是自己添加的一个字段
方法二:
给DEDE模板加了新功能 if判断功能 标签iif和elserun
增加了变量$str和$str_count $str是最终显示的内容 $str_count是循环显示内容的条数。
增加了标签iif 和 elserun 满足iif的条件就正常运行 如果不满iif的条件就运行elserun
如果不满足iif的条件,也没指定elserun就返回空白
iif和elserun都是正常的php语法.
{dede:arclist orderby='click' titlelen='30' row='10' iif="$str_count>1" elserun="$str=暂时没有内容"}
<li><span class="gptlink">[field:textlink/]</span></li>
{/dede:arclist}
运行结果 如果arclist没返回结果就显示 暂时没内容
<title>{dede:global name='cfg_webname' iif="strlen($str)>10" elserun="$str.='我的网站'"/} </title>
运行结果 如果cfg_webname长度大于10就正常显示
否则就在标题后面增加我的网站
显示
更改方法 只更改一个文件就是/dede/include/pub_dedetag.php
(1)搜索
foreach($GLOBALS[$arr] as $k=>$v){
更改成
$GLOBALS['autoindex']=0;
foreach($GLOBALS[$arr] as $k=>$v){
$GLOBALS['autoindex']++;
(2)搜索
$this->CTags[$i]->TagValue = $DedeMeValue;
}
在后面加上

01 $str = $this->CTags[$i]->TagValue;
02  
03 $str_count = $GLOBALS['autoindex'];
04  
05 if( $this->CTags[$i]->GetAtt("iif")!="" ){
06  
07 if(! eval("return {$this->CTags[$i]->GetAtt('iif')} ;" )){
08  
09 if($this->CTags[$i]->GetAtt("elserun")) {
10  
11 $this->CTags[$i]->TagValue=eval("return {$this->CTags[$i]->GetAtt('elserun')} ;" );
12  
13 }else{
14  
15 $this->CTags[$i]->TagValue='';
16  
17 }
18  
19 }
20  
21 }

织梦模板中使用php和if判断语句的技巧

猜你还喜欢

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论: