织梦dedecms调用正文的第一张图片代码有两种。
1、修改文件include/helpers/archive.helper.PHP,在文件最后添加:
/**
* 获得某文档的第一个图片
* https://www.360muye.cn/
* @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";//删除缩略图字符串最后七位,然后再补上后缀.jpg
return $str_sub;
}
在列表模板中通过以下代码调用:
[field:litpic function=firstimg('@me')/]
或者直接使用代码:
{dede:field name='litpic' function="firstimg(@me)"/}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。