详情页

帝国cms列表页图片调用判断无图则不显示

时间:2023年12月24日

编辑:佚名

列表页调用了标题图片。但是有的文章没有标题图片会默认显示notimg.gif比较难看, 如何在列表内容模板list.var里让代码自动判断有图片的就显示。没有图片的的文章不显示默认的notimg.gif。
点击复制代码 PHP
正确写法如下:
if(empty($r[titlepic]))
{
$titlepic=' ';
}
else
{
$titlepic='<a href="[!--titleurl--]"><img src="[!--titlepic--]"/></a>';
}
//-----------------上面的判断是否有图片-------------------
$nsmalltext=$r[smalltext];
$ntext=strip_tags($nsmalltext);//去除内容简介里的HTML标签
$newtext=esub($ntext,100,'...') ;//限制100字
$keyboard=$r[keyboard];
$r_tag=explode(",",$keyboard);
$tempid=1;//这里是搜索模板ID
for($i=0;$i<count($r_tag);$i++)
        {
             if($r_tag[$i])
                {
                        $tagslink=$public_r[newsurl]."e/tags/?tagname=".$r_tag[$i];//链接
                        $tagslink=$public_r[newsurl]."e/search/?searchget=1&tbname=$tbname&tempid=$tempid&show=keyboard&keyboard=".$r_tag[$i];//如果链接到搜索页面用此行代码,如果不是请删除
                        $tags.="<a href='$tagslink' target='_blank'>".$r_tag[$i]."</a> ";
                }
        }
//----------上面是调取关键字,如果你没有这个需要上面就省略掉-----------
$listtemp='<div id="listBox">
  <div class="listBoxTop">
    <div class="listBoxComment"> <span class="countComments">[!--plnum--]</span> <span
class="txtComments">&nbsp;Comments</span> </div>
    <div class="listBoxTitle">
      <h2><a href="[!--titleurl--]"
title="[!--oldtitle--]">[!--title--]</a></h2>
      <span class="timeAuthor"> 发布于:<small> [!--newstime--] </small>&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;发布者:<small>[!--username--] </small> </span> </div>
  </div>
  <div class="listBoxCenter">'.$titlepic.'
    <p class="articleIntro">[!--smalltext--]</p>
    <p class="readMore"><a
href="[!--titleurl--]">+阅读全文</a></p>
  </div>
  <div class="listBoxBottom"> <small class="listBoxBottomTag">标签:'.$tags.' </small> </small> <small class="listBoxBottomClick">日志分类:<a target="_blank"
href="[!--this.classlink--]">[!--this.classname--]</a>围观群众:[!--onclick--]人 </small> </div>
</div>';
相关文章
猜你需要