这是php文件,请问如何在内容模板中写标题和内容呢?请大神给写一个单条内容的模板。谢谢了,,由于代码太长,我删了一部份,急用,谢谢各位好心人了
spargs('uid')){ $uid = (int) $this->spargs('uid'); $cond = and b.uid = '$uid'; } if($this->spargs('pagelimit')){ $pagelimit = ($this->spargs('pagelimit') spargs('pagelimit') : 30 ; //自定义分页 }else{ $pagelimit = $this->yb['show_page_num']; } //left join `.dbpre.follow` as f on ( b.uid = f.touid and f.uid = '$uid' ) $sql = select b. * , k.id as likeid ,m.username,m.domain from `.dbpre.blog` as b left join `.dbpre.likes` as k on ( b.bid = k.bid and k.uid ='$this->uid' ) left join `.dbpre.member` as m on b.uid = m.uid where b.open = 1 $cond order by b.time desc; $data['blog'] = spclass('db_blog')->sppager($this->spargs('page',1),$pagelimit)->findsql($sql); $data['page'] = spclass('db_blog')->sppager()->getpager(); unset($data['page']['all_pages']); if(!empty($data['blog'])){ foreach($data['blog'] as &$d){ $this->foramt_feeds($d); } $this->api_success($data); }else{ $this->api_success(); } } //获取单个博客 function getoneblog(){ $bid = (int) $this->spargs('bid'); $sql = select b. * , k.id as likeid ,m.username,m.domain from `.dbpre.blog` as b left join `.dbpre.likes` as k on ( b.bid = k.bid and k.uid ='$this->uid' ) left join `.dbpre.member` as m on b.uid = m.uid where b.open in (1,-2) and b.bid = '$bid'; $data['blog'] = spclass('db_blog')->findsql($sql); foreach($data['blog'] as &$d){ $this->foramt_feeds($d,0); } $this->api_success($data); } //获取我关注的用户feeds function followfeeds(){ $followuid = spclass('db_follow')->getfollowuid($this->uid); if($followuid){ $sql = select b. * , k.id as likeid ,m.username,m.domain from `.dbpre.blog` as b left join `.dbpre.likes` as k on ( b.bid = k.bid and k.uid ='$this->uid' ) left join `.dbpre.member` as m on b.uid = m.uid where b.open = 1; $sql .= and b.uid in ($followuid) and b.open=1 order by b.time desc; $data['blog'] = spclass('db_blog')->sppager($this->spargs('page',1),10)->findsql($sql); $data['page'] = spclass('db_blog')->sppager()->getpager(); foreach($data['blog'] as &$d){ $this->foramt_feeds($d); } } $this->api_success($data); } /*获取随机推荐图片列表,首页用的*/ function recommendimg(){ $type = 3; //获取图像 $cachename = 'recommend_shuffle_'.$type; if(!spaccess('r',$cachename)){ $recommend = spclass('db_blog')->recommend_shuffle($type); foreach($recommend as $d){ $body = split_attribute($d['body']); if(is_array($body['attr']['img'])){ foreach($body['attr']['img'] as $img){ $imgs[] = array('bid'=>$d['bid'], 'uid'=>$d['uid'], 'img'=>$img['url'], 'username'=>$d['user']['username'], 'h_url'=>gouserhome(array('uid'=>$d['user']['uid'])), 'h_img'=>avatar(array('uid'=>$d['user']['uid'],'size'=>'small')), 'b_url'=>gouserblog(array('bid'=>$d['bid'],'domain'=>$d['user']['domain'],'uid'=>$d['user']['uid'])) ); } } } spaccess('w',$cachename,$imgs,86400); }else{ $imgs = spaccess('r',$cachename); } $count = count($imgs); $numbers = range (0,$count-1); shuffle($numbers); $queue = array_slice($numbers,0,1); $result = array(); foreach($queue as $d){ $result = $imgs[$d]; } $this->api_success($result); } //发现频道 随机发现最新的100个博客内容,取前15个 function discoverblog(){ $num = ($this->spargs('num')) ? $this->spargs('num') : 15; $page = ($this->spargs('page',0)) ? $num * ($this->spargs('page')-1) : 0; $isshuffle = ($this->spargs('isshuffle',0)) ? 1 : 0; $type = 'all'; $cachename = 'recommend_shuffle_'.$type; if(!spaccess('r',$cachename)){ $recommend = spclass('db_blog')->recommend_shuffle($type,150);//条数 15*10 $data = array(); foreach($recommend as $d){ $body = split_attribute($d['body']); if($d['type'] == 1){ $d['attr'] = ' '; } if($d['type'] == 3){ $d['attr'] = $body['attr']['img'][0]['url']; } if($d['type'] == 2 || $d['type'] == 4){ if(!empty($body['attr'])){ if(is_array($body['attr'])){ if( count($body['attr']) $d['bid'], 'title'=>$d['title'], 'body'=>utf8_substr(strip_tags($body['body']),0,120), 'type'=>$d['type'], 'uid'=>$d['uid'], 'username'=>$d['user']['username'], 'b_url'=>gouserblog(array('bid'=>$d['bid'],'domain'=>$d['user']['domain'],'uid'=>$d['user']['uid'])), 'tag'=>($d['tag'] != '') ? array_shift((explode(',',$d['tag']))) : '', 'img'=>$d['attr'] ); } } unset($recommend); spaccess('w',$cachename,$data,86400); }else{ $data = spaccess('r',$cachename); } $count = count($data); $numbers = range (0,$count-1); if($isshuffle){ shuffle($numbers); } $queue = array_slice($numbers,$page,$num); $result = array(); foreach($queue as $d){ $result[] = $data[$d]; } unset($data); $this->api_success($result); } /*发现频道 随机发现20个tag model 已缓存*/ function discovertag(){ $tags = spclass('db_tags')->discovertag(); $maxhit = 0; foreach($tags as &$d){ if($d['hit'] > $maxhit){ $maxhit = $d['hit']; } if(is_array($d['ulist'])){ foreach($d['ulist'] as &$list){ $list['h_url'] = gouserhome(array('uid'=>$list['uid'], 'domain'=>$list['domain'])); $list['h_img'] = avatar(array('uid'=>$list['uid'],'size'=>'small')); } } } $data = array(); $data['maxhit'] = $maxhit; $data['data'] = $tags; $this->api_success($data); } /*推荐频道 推荐用户*/ function recommenduser(){ //如果是自动推荐模式 if($this->yb['recomm_switch'] != 1){ $data = spclass('db_tags_blog')->finduserbytid($this->spargs(),$this->uid); foreach($data['data'] as & $d){ $d['h_url'] = gouserhome(array('uid'=>$d['uid'], 'domain'=>$d['domain'])); $d['h_img'] = avatar(array('uid'=>$d['uid'],'size'=>'big')); $d['logtime'] = ybtime(array('time'=>$d['logtime'])); $d['sign'] = strip_tags($d['sign']); $d['isfollow'] = ($d['isfollow'] == $this->uid) ? true: false; $d['blogtag'] = ($d['blogtag'] != '' ) ? explode(',',$d['blogtag']) : ''; } }else{ } $this->api_success($data); } /*首页获取评论*/ function reply(){ $bid = $this->spargs('bid'); $result = spclass('db_replay')->splinker()->sppager($this->spargs('page',1),$this->spargs('limit',10))->findall(array('bid'=>$bid),'time desc',''); $pager = ''; $data = array(); $data['page'] = spclass('db_replay')->sppager()->getpager(); foreach($result as &$d){ $d['msg'] = strip_tags(strreplaces($this->parse_uid($d['msg']))); $d['h_url'] = gouserhome(array('uid'=>$d['uid'], 'domain'=>$d['domain'])); $d['h_img'] = avatar(array('uid'=>$d['uid'],'size'=>'small')); $d['time'] = ybtime(array('time'=>$d['time'])); $d['del_flag'] = islogin() ? 1:0; $d['rep_flag'] = ( $this->uid != $d['uid'] && $this->uid != '') ? 1:0; } $data['body'] = $result; $this->api_success($data); } //处理feeds给前端显示 //$split 是否截断内容 private function foramt_feeds(& $d,$split=1){ $d['more'] = 0; $d['h_url'] = gouserhome(array('uid'=>$d['uid'], 'domain'=>$d['domain'])); $d['h_img'] = avatar(array('uid'=>$d['uid'],'size'=>'middle')); $d['b_url'] = gouserblog(array('bid'=>$d['bid'],'domain'=>$d['domain'],'uid'=>$d['uid'])); $d['tag'] = ($d['tag'] != '') ? explode(',',$d['tag']) : ''; $d['time_y'] = date('y.m',$d['time']); $d['time_d'] = date('d',$d['time']); $d['time'] = ybtime(array('time'=>$d['time'])); $rs = split_attribute($d['body']); $d['attr'] = $rs['attr']; $d['repto'] = $rs['repto']; if(!empty($d['repto'])){ $d['repto']['h_url'] = gouserhome(array('uid'=>$d['repto']['uid'], 'domain'=>$d['repto']['domain'])); $d['repto']['h_img'] = avatar(array('uid'=>$d['repto']['uid'],'size'=>'small')); }else{ $d['repto'] = null; } if($split == 1){ $d['body'] = utf8_substr(strip_tags($rs['body'],'
'),0,500); }else{ $d['body'] = strip_tags($rs['body'],'
'); } if($d['body'] == false){ $d['body'] = ''; } $d['more'] = (utf8_strlen($rs['body']) > 500) ? 1: 0; //处理音乐和视频 if($d['type'] == 2 || $d['type'] == 4){ if(count($d['attr']) > 4){ $d['mode'] = 1; if($split == 1){ $d['attr'] = array_slice($d['attr'],0,4); } } } //处理图片,超过10个就任务more if($d['type'] == 3){ if($split == 1){ if($d['attr']['count'] > 10){ $d['attr']['img'] = array_slice($d['attr']['img'],0,10); $d['mode'] = 1; } } } //如果显示全部则把more改成0 if($split != 1){ $d['show_reply'] = 1; //展开评论 } } }
回复讨论(解决方案) 你贴出的代码只是如何取得数据
并没给出数据如何写到模板
你贴出的代码只是如何取得数据
并没给出数据如何写到模板
这是模板是js调用的,我不想用js调用,想直接写到模板里
{include file=theme/default/header.html titles=$data.title}{include file=require_models_js.html} {include file=theme/default/userheader.html} {if !empty($data.0.tag)} {foreach $data.0.tag as $d} {$d} {/foreach} {/if}
{if isset($adunit.6) && $adunit.6.is_show == 1}
{/if} 谁喜欢{$fava.count}
{if $fava.count !=0} {foreach from=$fava.rs item=d} {/foreach}
{/if}
{include file=theme/default/aside.html}
{include file=theme/default/footer.html}
那就需要看到到达浏览器的 html 代码,并从其中分析出数据是如何读取的
那就需要看到到达浏览器的 html 代码,并从其中分析出数据是如何读取的 您看一下这个网站www.shanzhaicun.com
好像就是这个 yb_load_feeds 函数吧,贴出他的代码
你那些紧凑格式的 js 看得人头发晕
好像就是这个 yb_load_feeds 函数吧,贴出他的代码
你那些紧凑格式的 js 看得人头发晕 我也找不到这个在哪里
好像就是这个 yb_load_feeds 函数吧,贴出他的代码
你那些紧凑格式的 js 看得人头发晕 看到这样的代码是不是您要看的
template('feed_template', '{each blog as data i} {include tpl_header_define(\'header\') data} {include tpl_feed_define(data.type) data} {if data.show_reply ==1} {include tpl_header_define(\'infooter\') data} {else} {include tpl_header_define(\'footer\') data} {/if}
{/each}');template('tmpl_model_header', '{time_y}
{time_d}
{if top ==1}[\u7f6e\u9876]{/if}{if title != null}{title}{/if}
');template('tmpl_model_1', ' {if attr.length >0} {each attr as img i} {if i 0} {each attr as m i} {if m.type == \'local\'}
{m.title} - {m.author}
\u4e0b\u8f7d\u97f3\u4e50
{/if} {if m.type == \'xiamisearch\' || m.type == \'xiami\'}
{if m.title != \'null\' && m.author != \'null\'} {m.title} {m.author}
{/if} \u5f39\u51fa\u64ad\u653e
{if m.type == \'xiami\'} {else} {/if}
{/if} {if m.type == \'yinyuetai\'} {m.title}
{m.author}
{/if} {/each} {/if} {if body} {body}
{/if}
');