tags: [] tags: []
实现emlog列表缩略图先调用正文第一张图片,没有则调用附件图片,如果前两者都没有则调用随机图片第一步:首先在模板的module.php文件中最后面加入如下代码 <?php //全局匹配正文中的图片并存入imgsrc中 function img_zw(content) { preg\_match\_all("|<img\[^>\]+src=\\"(\[^>\\"\]+)\\"?\[^>\]\*>|is", content, imgsrc = !empty(img\[1\]) ? img[1][0] : ”; if(imgsrc; endif; } //Custom: 获取附件第一张图片 function img_fj(logid) { db = MySql::getInstance(); logid.” AND (filepath LIKE ‘%jpg’ OR filepath LIKE ‘%gif’ OR filepath LIKE ‘%png’) ORDER BY aid ASC LIMIT 0,1”; db->query(img_path = ""; while(db->fetch_array(imgs)) { img_path .= BLOG_URL.substr(row\['filepath'\],3,strlen(row[‘filepath’])); } return img\_path; } ?> 第二步:然后在log\_list.php的foreach循环中加入如下代码 <?php if(img\_zw(value[‘content’])) { value[‘content’]); } elseif(img_fj(value\['logid'\])) { imgurl = img_fj(value\['logid'\]); } else { imgurl = TEMPLATE_URL.‘images/‘.rand(1,5).‘.jpg’; } ?> <p><img src=“https://www.oveblog.pages.dev/<?php echo $imgurl;?>” /></p> , ,