我准备在zblog php1.4发布后,将个人博客www.liangxin.name的模版出个zblog版的,但是首页幻灯片的数据调用要首先准备好,别的就比较好改了!以下是我写的一个数据调用的代码,感觉有点繁琐,如能简化一下就好了,如下为我的首页幻灯片数据调用样式:
在emlog下,这个数据就是调用了最新文章,但是如果有置顶文章的话就会优先显示,下面的代码可以实现这一功能,但是我需要的是最简洁最高效的执行代码:
{php} $pattern="/<[img|IMG].*?src=[\'|\"](.*?(?:[\.gif|\.jpg|\.png]))[\'|\"].*?[\/]?>/"; $content = $article->Content; preg_match_all($pattern,$content,$matchContent); if (count($matchContent[1]) > 0){ if($matchContent[1][0]){$temp=$matchContent[1][0];} }else{$temp="$host/zb_users/theme/$theme/style/images/nopic.jpg";} $order = array('log_PostTime'=>'DESC'); $where = array(array('=','log_Status','0')); $array = $zbp->GetArticleList(array('*'),$where,$order,array(8),''); {/php} {foreach $array as $newlist} {if $newlist.IsTop} <li class="new"><img src="{$temp}" alt="{ $newlist.Title}" /><a href="{$newlist.Url}" title="{$newlist.Title}"> 【置顶】: {php} echo $Title= preg_replace('/[\r\n\s]+/', '', trim(SubStrUTF8(TransferHTML($newlist->Title,'[nohtml]'),18)).''); {/php}</a></li> {else} <li class="new"><img src="{$temp}" alt="{ $newlist.Title}" /><a href="{$newlist.Url}" title="{$newlist.Title}"> 【最新】: {php} echo $Title= preg_replace('/[\r\n\s]+/', '', trim(SubStrUTF8(TransferHTML($newlist->Title,'[nohtml]'),18)).''); {/php}</a></li> {/if} {/foreach}
以上代码是根据最新文章模版搞出来的,能实现全站最新数据的调用,同时兼顾置顶推荐功能,因为目前1.4没有出来,无法测试,所以大体弄这个出来,但是支持1.3php的。以下为我本地测试调用出来的数据样式,还未增加js和css样式文件,所以还不是幻灯片,但是需要的数据已经出来了。
- 本文固定链接: https://www.liangxin.name/sitebuild/zblog/2015/01/31/?p=1016.html
- 转载请注明: xindao 于 心岛博客 发表