在做zblog网站的有时候模板需要调用分类列表文章展示在网站的首页或者文章页,又不想下载插件什么的,
下面给大家分享一个指定分类列表文章简单的调用代码:
{foreach GetList(列表文章数,分类id) as $article}{template:thumbnail}
<li><div class="recent-posts-img">
<a href="{$article.Url}" title="{$article.Title}">
<img src="{$temp}" alt="{$article.Title}" class="thumbnail"/></a></div>
<div class="recent-posts-title">
<h4 class="title">
<a href="{$article.Url}" title="{$article.Title}">{$article.Title}</a></h4>
<span class="info" ><i class="icon-calendar-1"></i>{$article.Time('Y-m-d')}</span>
</div></li>{/foreach}只需要修改代码中的分类id和列表文章数就可以调用处zblog php的分类文章列表。
上面调用显示效果如下:

上面代码调用了文章中的第一张图片,要实现这个功能需要在主题中增加模板文件:thumbnail.php
文件里面添加如下代码:
{php}$temp=mt_rand(1,3);$pattern="/<[img|IMG].*?src=[\'|\"](.*?(?:[\.gif|\.jpg|\.png]))[\'|\"].*?[\/]?>/";
$content = $article->Content;preg_match_all($pattern,$content,$matchContent);
if(isset($matchContent[1][0]))$temp=$matchContent[1][0];
else
$temp=$zbp->host."zb_users/theme/$theme/style/images/random/$temp.jpg";
//需要在相应位置放置4张jpg的文件,名称为1,2,3,4,5{/php}只需要在相应位置放置4张jpg的文件,名称为1,2,3,4,5
有图片的时候调用第一张图片,无图片的时候会自动调用主题目录里面的随机图片。
老鱼主题