打开ECSHOP网店根目录/includes/lib_article.php文件,并在最尾处增加以下代码:
/* * * 获取文章内容第一张图作为缩略图 * @Author ECSHOP.CX */ function GetImageSrc($body) { if (!isset($body)) { return 'images/ECSHOP_CX.png'; } else { preg_match_all ("/<(img|IMG)(.*)(src|SRC)=[\"|'|]{0,}([h|\/].*(jpg|JPG|gif|GIF|png|PNG))[\"|'|\s]{0,}/isU", $body, $out); return $out[4]; } }
调用代码如下:
$imgsrc = GetImageSrc($row['content']); $articles[$id]['img'] = $imgsrc[0];
效果截图
演示效果查看ECSHOP插件网:https://www.ecshop.cx/article_cat-15.html