EMLOG get a thumbnail picture of the article attachment Code

EMLOG post attachments thumbnail images can be generated in the annex library data table address is generated images with thum-, so when we use the code to call the article attached images, you can set conditions prior call thumbnails with thum-, if not thumbnail of the original call, if the original did not, it would call random picture settings; the specific implementation code as follows, before using the code, first create a new folder under a folder rand in the template file, which put random images, pictures name, the number of random images to be modified from 0.jpg 10.jpg in code, copy the code to module.php finally, the call to where it is needed.

  1. <?php
  2. // Get article thumbnail
  3. function lanye_logthum($logid){$db = Database::getInstance();$query = $db->query("SELECT * FROM ".DB_PREFIX."attachment WHERE blogid=".$logid." AND (`filepath` LIKE '%jpg' OR `filepath` LIKE '%gif' OR `filepath` LIKE '%png' OR `filepath` LIKE '%jpeg') ORDER BY `aid` ASC LIMIT 0,1");while($row = $db->fetch_array($query)){$imgpath = substr( $ Row [ 'filepaths' ], 3 , strlen ( $ row [ 'filepaths' ]));} $ Mgarr  =  explode ( "/" , $ imgpath ) $ imgsurl  =  $ Mgarr [ 0 ]. / ' . $ Mgarr [ 1 ]. / ' . $ Mgarr [ 2 ]. / thum- ' . $ Mgarr [ 3 ]; ow ( empty ( $ imgpath )) { $ randval = rand(0,10);return TEMPLATE_URL.'rand/'.$randval.'.jpg';}else{if(!file_exists(EMLOG_ROOT.'/'.$imgsurl)){return BLOG_URL.$imgpath;}else{return BLOG_URL.$imgsurl;}}}?>

Guess you like

Origin www.cnblogs.com/pz2133/p/11905892.html