王尘宇王尘宇

研究百度干SEO做推广变成一个被互联网搞的人

Typecho 幻灯片代码,核心图轮播

Typecho 幻灯片代码,核心图轮播


起首,让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="(.?)"1*>/i", $rs['text'], $thumbUrl);  //经由过程正则式猎取图片地点   $img_src = $thumbUrl1;  //将赋值给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";  //没找到(默许情况下),不输出任何内容   };}

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

然后,让typecho零丁挪用一个分类或许标签的文章列表

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


相关文章

评论列表

发表评论:
验证码

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。