首页 zblog内容详情

zblogphp调用指定文章方法(连续输入ID)

2026-01-08 4 897698882
zblogphp调用指定文章方法(连续输入ID)

站点名称:zblogphp调用指定文章方法(连续输入ID)

所属分类:zblog

官方网址:

SEO查询: 爱站网 站长工具

进入网站

站点介绍

zblogphp模板中经常会遇到调用指定文章标题、图片、摘要等,比如幻灯片轮播就是调用指定文章内的第一张图片,而导读、小编推荐等则多需要调用标题、摘要等。

分享出来刚发布的zblogphp主题精彩导读文章的调用:

新建了一个post-dd.php为模板:

<?php echo '404';die();?><div class="chosen"> <div class="com-title"><span><img src="{$host}zb_users/theme/{$theme}/style/images/symbol-4.png" alt="" />精选导读</span> </div> {php}$array = explode(',',$zbp->Config('ydlinux')->ydlinux_ddid);{/php} {foreach $array as $key=>$id} {$post=GetPost((int)$id);} {if $zbp->CheckPlugin('IMAGE')}{php}IMAGE::getPics($post,130,85,4){/php}{/if} {if $zbp->CheckPlugin('sf_img1')}{php}SF_img1::getPics($post,130,85,4){/php}{/if} {php}$postintro = trim(SubStrUTF8(TransferHTML($post->Intro,'[nohtml]'),38)).'...';{/php} {$i = $key+1} <div class="chosenbox {if $i==2||$i==4||$i==6}chosenbox-ml{/if}">  <div class="chosenimg"><a href="{$post.Url}" title="{$post.Title}" target="_blank"><img src="{if $zbp->CheckPlugin('IMAGE') && $post->IMAGE_COUNT>0}{$post.IMAGE[0]}{elseif $zbp->CheckPlugin('sf_img1') && $post->sf_img_count>0}{$post.sf_img[0]}{else}{ydlinux_thumbnail($post)}{/if}" alt="{$post.Title}" width="130" height="85" /></a>  </div>  <h3><a href="{$post.Url}" title="{$post.Title}" target="_blank">{$post.Title}</a></h3>  <p>{$postintro}</p>  <p><span></span>  </p> </div> {/foreach} <div class="floatfix"></div></div>

说明:

1、$zbp->Config('ydlinux')->ydlinux_ddid为主题配置内可调用的文章ID,多ID用英文小逗号隔开。

2、使用了缩略图插件判断,如果启用了sf_img1或者IMAGE缩略图插件,则调用插件生成的图片,如果没有,则直接调用{ydlinux_thumbnail($post)}。 其中$post就不需要说了,ydlinux_thumbnail($post)需要在include.php中写入:

//原图function ydlinux_thumbnail($related) {    global $zbp;  $temp=mt_rand(1,10); $pattern="/<[img|IMG].*?src=[\'|\"](.*?(?:[\.gif|\.jpg|\.png]))[\'|\"].*?[\/]?>/"; $content = $related->Content;  preg_match_all($pattern,$content,$matchContent); if(isset($matchContent[1][0])){  $thumb=$matchContent[1][0];  }else{  $thumb=$zbp->host . "zb_users/theme/" .$zbp->theme. "/include/random/" .$temp. ".jpg"; }    return $thumb;}

注:ydlinux为主题应用ID,需要修改为自己的模板ID。