dedecms织梦获取文章里第一张图片
类别:建站知识   时间:04-25

dedecms织梦获取文章里第一张图片1、在include/helpers/archive.helper.php/*** 获得某文档的第一个图片** @param int $aid 文档id* @return string*/if( ! function_exists('GetImgs')){function GetImgs($aid){global $dsql;$query = "select body FROM `dede_addonarticle` where aid='$aid'";$dsql->Execute('body',$query);$row = $dsql->GetArray('body');preg_match('/<img(.*)>/i',$row['body'],$str);$GImgs = $str[0];//echo $GImgs;return $GImgs;}}模板里调用[field:id function=GetImgs(@me)/]2、include/extend.func.php//取第一张图地址function firstimg($str_pic){$str_sub=substr($str_pic,0,-7).".jpg";//删除缩略图字符串最后七位,然后再补上后缀.jpgreturn $str_sub;}然后在模板里循环调用:[field:litpic function=firstimg('@me')/]如要直接调用用:{dede:field name='litpic' function="firstimg(@me)"/}

智慧半岛,是一家专注于青岛网站建设青岛网站开发的青岛网络公司,Copyright ©2007-2019 Ebandao.Cn 版权所有 All Rights Reserved.(建议在1366x768以上的浏览器中访问)鲁ICP备08014496号

13153297890