zblog php通过代码实现首页调用缩略图的方法

我们在搭建zblog php网站的时候需要在首页进行文章缩略图的调用,之前zblog asp版一般都是通过缩略图插件来实现的。

zblog php可以通过代码的方式更好的实现。

判断语句代码:

PHP
{php}
              $pattern="/<[img|IMG].*?src=[\'|\"](.*?(?:[\.gif|\.jpg|\.png]))[\'|\"].*?[\/]?>/";//判断文章是否含有图片 $content = $article->Content; preg_match_all($pattern,$content,$matchContent); {/php} {if isset($matchContent[1][0])} {template:post-multi-t-index}//有图模板 {else} {template:post-multi-w-index}//无图模版 {/if}

有图模板代码:

PHP
<ul class="clearfix"> <h1><a href="{$article.Url} " target="_blank">{$article.Title}</a> <span>{$article.Category.Name}</span> </h1> <li> <p ><a href="{$article.Url}" title="{$article.Title}"><img src="{$matchContent[1][0];}" style="float:left;" width="120" height="75" /></a> {php} $temp = preg_replace('/[\r\n\s]+/', '', trim(SubStrUTF8(Transferhtml($article->Intro,'[nohtml]'),150)).'...'); {/php} {$temp} </p> </li></ul>

无图模板代码:

PHP
<ul class="clearfix"> <h1><a href="{$article.Url} " target="_blank">{$article.Title}</a> <span>{$article.Category.Name}</span> </h1> <li> <p > {php} $temp = preg_replace('/[\r\n\s]+/', '', trim(SubStrUTF8(Transferhtml($article->Intro,'[nohtml]'),150)).'...'); {/php} {$temp} </p> </li></ul>

猜你喜欢

转载自www.cnblogs.com/cg123/p/11979792.html
今日推荐