服务报价 | 域名主机 | 网络营销 | 软件工具| [加入收藏]
 热线电话: #
当前位置: 主页 > php教程 > dedecms教程 >

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

时间:2017-01-03 11:02来源:未知 作者:最模板编辑 点击:
dedecms织梦获取文章里第一张图片 1、在include/helpers/archive.helper.php /** * 获得某文档的第一个图片 * * @param int $aid 文档id * @return string */ if( ! function_exists(GetImgs)) { function GetImgs($aid) { global
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)
0%
踩一下
(0)
0%
------分隔线----------------------------