DedeCMS标签 PHP判断语句写法

时间:2023-03-08 17:01:01

缩略图标签的判断写法,如果有图片就显示,没图片就显示别的。

{dede:field name=litpic runphp='yes'}
if(!empty(@me))
{
@me="<img src=".@me." height=缩略图高度 width=缩略图宽度 />";
}
else
{
@me="这里是没有图片你想代替显示的内容";
}
{/dede:field}
     在开发时自定义内容模型某字段为图片时,在前台标签调时,调用结果如下:
{dede:img text='' width='990' height='313'} /uploads/allimg/ www.juhutang.com /ico_1.jpg {/dede:img}
而我只要图片URL地址(即红色部分),其他多余的内容不需要显示。 [field:p1 runphp='yes']
$ndtp = new DedeTagParse(); // 新建解析类
$ndtp->LoadSource(@me); // 加载当前标签 即:{dede:img text='' width='990' height='313'} /uploads/allimg/ www.juhutang.com /ico_1.jpg {/dede:img}
$ntag = $ndtp->GetTag("img"); // 找到 "img" 标签
@me = trim($ntag->GetInnerText()); // 提取 img 标签中的内容并返回。
[/field:p1]