Zblog中Radom随机图片调用的两种方法(列表页和内页)
1.列表页:无图时显示随机图片,有图时显示文章内第一张图片
//常用调用随机图片{php}
$temp=mt_rand(1,33);
$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/pic/gx$temp.jpg";
{/php}
调用代码如下PHP
<p style="text-align:center;"><img src="{$temp}" alt="{$article.Title}"/></p>
2.内容页:无图时显示随机图片,有图时不显示任何图片
放在页首的代码
{php}
$temp=mt_rand(1,33);
$pattern="/<[img|IMG].*?src=[\'|\"](.*?(?:[\.gif|\.jpg|\.png]))[\'|\"].*?[\/]?>/";
$content = $article->Content;
preg_match_all($pattern,$content,$matchContent);
$temp=$zbp->host."zb_users/theme/pic/gx$temp.jpg";
{/php}
调用代码如下
{if isset($matchContent[1][0])}
{else}
<p style="text-align:center;">
<img src="{$temp}" alt="{$article.Title}"/>
</p>
{/if}

wys![[F]laughing[/F]](http://www.noteet.com/zb_users/theme/Lucky/source/face/laughing.gif)