<div class="post-content"> <div class="post-excerpt"> <?php $this->excerpt(360, ' ... '); ?> <p class="more"><a href="<?php $this->permalink(); ?> " title="<?php $this->title(); ?> ">阅读剩下更多</a></p> </div> <div class="post-thumbnail"> <?php Thumbnail_Plugin::show($this); ?> </div> </div> <p class="post-meta"> <span class="post-views">阅读 (<?php Views_Plugin::theViews('', '', 1); ?> )</span> <a href="<?php $this->permalink(); ?> /#comments" class="post-comments ds-thread-count" data-thread-key="<?php echo $this->cid; ?> " data-count-type="comments"></a>
/** * 从附件中获取上传的最后一张图 * * 语法: Thumbnail_Plugin::show($this); * * @access public * @param int $obj $this * @return string $img 缩略图的地址 */ public static function show($obj) { $options = Typecho_Widget::widget('Widget_Options'); $url_plugin = $options->pluginUrl . '/Thumbnail/'; //插件地址 -> http://domain.com/usr/plugins/Thumbnail/ $url_resource = $options->resourceUrl; //资源地址 -> http://domain.com/usr/resources/ $dir_resource = "/" . str_replace($options->siteUrl, "", $url_resource); //资源路径 -> /usr/resources/ /********* 以下可以自定义 ************/ $dir_cate = $dir_resource . "cate/"; // 分类图片相对位置 -> /usr/resources/cate/ $dir_rand = $dir_resource . "rand/"; // 随机图片相对位置 -> /usr/resources/rand/ $default_img = $url_plugin . "default.png"; // 默认图片 -> http://domain.com/usr/plugins/Thumbnail/default.png $default_ext = '.png'; //默认分类图片类型 -> /usr/resources/cate/xxx.png $arr_ext = array('jpg', 'gif', 'png', 'bmp', 'jpeg'); //随机图片的后缀名 /********* 以上可以自定义 ************/ $cid = $obj->cid; $cate = $obj->category; $content = $obj->text; $img = $default_img; if (strpos($content, "<!--NoThumbnail-->") === false) { $db = Typecho_Db::get(); $attach = $db->fetchAll($db->select()->from('table.contents')->where('type = ? AND parent = ? ', 'attachment', $cid)); if (empty($attach)) { //没有附件的时候 从文章中匹配 /**↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓**/ preg_match_all("/\\<img.*?src\\=(\\'|\")(.*?)(\\'|\")[^>]*>/i", $content, $matches); $imgCount = count($matches[0]); if ($imgCount >= 1) { $img = $matches[2][0]; } else { if (file_exists($_SERVER['DOCUMENT_ROOT'] . $dir_cate . $cate . $default_ext)) { $img = $dir_cate . $cate . $default_ext; } else { $img = Thumbnail_Plugin::randPic($dir_rand, $default_img, $arr_ext); //随机图片 } } /**↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑**/ /***** 1、只从附件中读取,请将以上↓↑之间代码注释即可。 ******/ /***** 2、不存在附件时读分类图片,请将以上↓↑之间代码注释,并打开以下代码 if( file_exists( $_SERVER['DOCUMENT_ROOT'] . $dir_cate . $cate . $default_ext ) ){ $img = $dir_cate . $cate . $default_ext ; } *****/ } else { //直接从附件中找出第一个上传的图片 foreach ($attach as $attach) { $attach_text = unserialize($attach['text']); if (Thumbnail_Plugin::isImage($attach_text['type'], $arr_ext)) { $img = $attach_text['path']; break; } } } $img = $img; } else { $img = ""; } echo $img; }
?> <?php $i++; ?> <li><a href="<?php $relatedPosts->permalink(); ?> " title="<?php $relatedPosts->title(); ?> "> <img src="<?php $relatedPosts->options->themeUrl(); ?> timthumb.php?src=<?php Thumbnail_Plugin::show($relatedPosts); ?> &h=90&w=150&zc=1" /> <?php $relatedPosts->title(); ?> </a></li> <?php } ?> </ul> <?php if ($i == 0) { ?> <li>没有相关文章!</li> <?php
?> <?php while ($posts->next()) { ?> <li><a href="<?php $posts->permalink(); ?> " title="<?php $posts->title(); ?> "> <img src="<?php $posts->options->themeUrl(); ?> timthumb.php?src=<?php Thumbnail_Plugin::show($posts); ?> &h=150&w=310&zc=1" /> <span class="text"><?php $posts->title(); ?> </span> <span class="wid-tg-comment"><i class="fa fa-comments-o"></i> <?php $posts->commentsNum('%d 评论'); ?> </span> </a></li> <?php } ?>