欢迎来到润旭源码网
帮助中心

润旭源码网

热门搜索: 企业源码    免费源码   

dedecms织梦获取文章里第一张图片

  • 时间:2020-07-19 09:21 编辑: 来源: 阅读:160
  • 扫一扫,手机访问
摘要: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 FR

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";//删除缩略图字符串最后七位,然后再补上后缀.jpg

return $str_sub;

}

然后在模板里循环调用:

[field:litpic function=firstimg('@me')/]

如要直接调用用:

{dede:field name='litpic' function="firstimg(@me)"/}


  • 全部评论(0)
资讯详情页最新发布上方横幅
联系我们

QQ:888477 {点击直接联系}

邮箱:runxu123@qq.com

时间:周1——周6 【9:00-23:00

联系客服
购买源码 源码咨询 投诉建议 联系客服
0373-6621888
手机版

扫一扫进手机版
返回顶部