Typecho 随机缩略图函数分享
这个代码结果是附件有图片猎取第一个图片作为缩略图。
假如附件没有图片随机显现指定目次下的图片。
在主题下functions.php文件中到场以下代码:
function thumb($cid) {if (empty($imgurl)) {$rand_num = 10; //随机图片数目,依据图片目次中图片现实数目设置if ($rand_num == 0) {$imgurl = "随机图片寄存目次/0.jpg";//假如$rand_num = 0,则显现默许图片,须定名为"0.jpg",注重是相对地点 }else{$imgurl = "随机图片寄存目次/".rand(1,$rand_num).".jpg";//随机图片,须按"1.jpg","2.jpg","3.jpg"...的次序定名,注重是相对地点}} $db = Typecho_Db::get(); $rs = $db->fetchRow($db->select('table.contents.text') ->from('table.contents') ->where('table.contents.type = ?', 'attachment') ->where('table.contents.parent= ?', $cid) ->order('table.contents.cid', Typecho_Db::SORT_ASC) ->limit(1));$img = unserialize($rs['text']);if (empty($img)){ echo $imgurl;}else{ echo '你的博客地点'.$img['path'];}}在模板上挪用以下代码:
<?php echo thumb($this->cid); ?>以上文章来源于:http://app.typecho.me/coder/images.html

评论列表