Typecho Wiki
每一个作品都值得被记录

让 typecho 可以调文章中的图 幻灯片代码 焦点图轮播效果

Typecho维基君Typecho教程 • 3702次浏览 • 发布 2017-11-06 • 更新 2017-11-06
极致加速的V2Ray 助您畅享全球网络 & 搬瓦工VPS最新优惠码
🛜自用大流量超低月租手机卡推荐榜单 #拒绝流量焦虑

首先,让typecho可以调文章中的第一张图或者附件图片

function img_postthumb($cid) {
$db = Typecho_Db::get();
$rs = $db->fetchRow($db->select('table.contents.text')
->from('table.contents')
->where('table.contents.cid=?', $cid)
->order('table.contents.cid', Typecho_Db::SORT_ASC)
->limit(1));
 
preg_match_all("/\<img.*?src\=\"(.*?)\"[^>]*>/i", $rs['text'], $thumbUrl);  //通过正则式获取图片地址
$img_src = $thumbUrl[1][0];  //将赋值给img_src
$img_counter = count($thumbUrl[0]);  //一个src地址的计数器
 
switch ($img_counter > 0) {
case $allPics = 1:
echo $img_src;  //当找到一个src地址的时候,输出缩略图
break;
default:
echo "http://baidu.com/404";  //没找到(默认情况下),不输出任何内容
};
}
</img.*?src\=\"(.*?)\"[^>

请添加到你模版文件夹中的【functions.php】文件中,直接往文件后面空白处插

然后,让typecho单独调用一个分类或者标签的文章列表

<ul>
<?php $this->widget('Widget_Archive@indexfocus', 'pageSize=6&type=tag', 'slug=focus')->to($indexfocus); ?><?php while($indexfocus->next()): ?>
<li><a href="<?php $indexfocus->permalink(); ?>" target="_blank"><img src="<?php echo img_postthumb($indexfocus->cid,4); ?>" alt="<?php $indexfocus->title() ?>" /><strong><?php $indexfocus->title() ?></strong></a></li>
<?php endwhile; ?>
</ul>

广告声明:文内含有的对外跳转链接(包括不限于超链接、二维码、口令等形式),用于传递更多信息,节省甄选时间,结果仅供参考,Typecho.Wiki所有文章均包含本声明。
本文检索关键词:typecho
厂商投放

【腾讯云】🎉五一云上盛惠!云服务器99元/月续费同价!

腾讯云五一劳动节海量产品 · 轻松上云!云服务器首年1.8折起,买1年送3个月!超值优惠,性能稳定,让您的云端之旅更加畅享。快来腾讯云选购吧!

广告
添加新评论 »