zblogPHP幻灯片调用方法(连续输入文章ID调用指定文章)
今天分享制作zblog模板过程中,经常需要用到的幻灯片调用。
幻灯片目前的方式我主要用两种:
1、后台主题配置内直接单独上传图片,输入标题、网址。
2、直接输入要调用的文章ID,直接调取文章内的图片为幻灯片,这种方式用的越来越多,懒人模式嘛,很多人没有太多精力经常去做图,所以直接输入文章ID是最为省心的方法了。
下面分享下直接输入文章ID调用幻灯片的方法:
{php} $hdpid = explode(',',$zbp->Config('ydimg')->ydimg_hdpid); foreach($hdpid as $id){ $post=GetPost((int)$id); $pattern="/<[img|IMG].*?src=[\'|\"](.*?(?:[\.gif|\.jpg|\.png]))[\'|\"].*?[\/]?>/"; $content = $post->Content; preg_match_all($pattern,$content,$matchContent); if(isset($matchContent[1][0])) $temp=$matchContent[1][0]; else $temp="{$host}zb_users/theme/{$theme}/style/images/wutu.png"; {/php} <li><a href="{$post.Url}"><img src="{$temp}" alt="{$post.Title}" /></a> </li> {php} } {/php}第一行的:$zbp->Config('ydimg')->ydimg_hdpid 需要在主题配置内写入。
使用方法为连续输入文章ID,多ID用英文小逗号隔开。
其实这种调用方法非常简单,可以说太简单了,直接用下面这段也是可以的:
{php}$array = explode(',',$zbp->Config('ydit')->ydit_hdpid);{/php}{foreach $array as $key=>$id}{$post=GetPost((int)$id);} <li><a href="{$post.Url}" title="{$post.Title}" target="_blank">{$post.Title}</a></li>{/foreach}调用指定文章。