这是php文件,请问如何在内容模板中写标题和内容呢?请大神给写一个单条内容的模板。谢谢了,,由于代码太长,我删了一部份,急用,谢谢各位好心人了
<?phpclass blog extends top{ function __construct(){ parent::__construct(); } //获取feeds function feeds(){ if($this->spArgs('uid')){ $uid = (int) $this->spArgs('uid'); $cond = "and b.uid = '$uid'"; } if($this->spArgs('pagelimit')){ $pageLimit = ($this->spArgs('pagelimit') < 30) ? $this->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']) <= 1){ if($body['attr']['type'] == 'yinyuetai'){ //对音乐台特殊处理 $d['attr'] = 'index.php?c=blog&a=getyytimg&src=' . $body['attr']['img']; }else{ $d['attr'] = $body['attr']['img']; //将图片返回给前台 } }else{ if($body['attr'][0]['type'] == 'yinyuetai'){ //对音乐台特殊处理 $d['attr'] = 'index.php?c=blog&a=getyytimg&src=' . $body['attr'][0]['img']; }else{ $d['attr'] = $body['attr'][0]['img']; //将图片返回给前台 } } } }else{ $d['attr'] =$body['attr']; } } if($d['attr']){ $data[] = array('bid'=>$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'],'<br><p><embed>'),0,500); }else{ $d['body'] = strip_tags($rs['body'],'<br><p><embed>'); } 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"}<div id="wrap"> <div id="main"> {include file="theme/default/userheader.html"} <div id="mytag"> {if !empty($data.0.tag)} {foreach $data.0.tag as $d} <li><a href="{spUrl c=blog a=tag tag=$d}"><span>{$d}</span></a></li> {/foreach} {/if} <div class="clear"></div> </div> <div id="feedArea"> <script type="text/javascript"> $(document).ready(function(){ yb_load_feeds('blog','getOneBlog',{ bid:{$bid} } ); }) </script> <div id="feed_loading"></div> <div id="feed_box"></div> <div class="clear"></div> {if isset($adunit.6) && $adunit.6.is_show == 1} <div id="ad_theme_list"></div> <script> $(document).ready(function(){ ad_aside('#ad_theme_list',6); setInterval(function(){ ad_aside('#ad_theme_list',6); }, 30000); }) </script> {/if} <div class="favatitle">谁喜欢<span>{$fava.count}</span></div> {if $fava.count !=0} <div class="fava"> {foreach from=$fava.rs item=d} <a href="{goUserHome domain=$d.domain uid=$d.uid}" title="{$d.username} - {ybtime time=$d.time}"><img src="{avatar uid=$d.uid size=small}" alt="{$d.username}"/></a> {/foreach} <div class="clear"></div> </div> {/if} <div id="comment"></div> <script> $(document).ready(function(){ loadCommend('comment',{$bid}); }); </script> </div> </div> <div id="aside"> {include file="theme/default/aside.html"} </div></div>{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} <div class="box" id="blog_{data.bid}"> {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} <div class="clear"></div> </div> {/each}');template('tmpl_model_header', '<div class="date"><div class="month">{time_y}</div><div class="day">{time_d}</div></div> <div class="title" id="box_title"><a href="{b_url}">{if top ==1}[\u7f6e\u9876]{/if}{if title != null}{title}{/if}</a></div>');template('tmpl_model_1', '<div id="feedText_{bid}" class="content"> <div class="text_area_all"> <p> {if attr.length >0} {each attr as img i} {if i <1} <img src="{img}" style="max-width:90%"/ alt="请问如何在内容模板中写标题和内容呢" >{/if} {/each} {/if} {body}</p> <div class="clear"></div> </div> </div>');template('tmpl_model_2', '<div id="feedText_{bid}" class="content"> {if attr.length > 0} {each attr as m i} {if m.type == \'local\'} <div class="album" id="swf_cover_{bid}_{i}"> <div class="cover"> <div class="cover_img"></div> <img src="{m.img}"/ alt="请问如何在内容模板中写标题和内容呢" > </div> <div class="cover_title">{m.title} - {m.author}</div> <div class="cover_fun"><a href="javascrpt:void(0)" onclick="window.location.href={urlpath()}/{m.url}"><span class="download">\u4e0b\u8f7d\u97f3\u4e50</span></a></div> <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="340" style="max-width:90%"> <param name="movie" value="{flashpath(m.url)}" /> <param name="quality" value="high" /> <param value="transparent" name="wmode" /> <embed src="{flashpath(m.url)}" width="340" height="33" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed> </object> </div> {/if} {if m.type == \'xiamisearch\' || m.type == \'xiami\'} <div class="album"> <div class="cover"> <div class="cover_img"></div> <img src="{m.img}" / alt="请问如何在内容模板中写标题和内容呢" > </div> {if m.title != \'null\' && m.author != \'null\'} <div class="cover_title"> <a href="{h_url}">{m.title} {m.author}</a> </div> {/if} <div class="cover_fun"> <a href="{m.url}" target="_blank"><span class="eject">\u5f39\u51fa\u64ad\u653e</span></a> </div> {if m.type == \'xiami\'} <embed src="http://www.xiami.com/widget/0_{m.pid}/singlePlayer.swf" type="application/x-shockwave-flash" width="340" style="max-width:90%" wmode="transparent"></embed> {else} <embed src="{m.pid}" type="application/x-shockwave-flash" width="340" height="33" wmode="transparent"></embed> {/if} </div> {/if} {if m.type == \'yinyuetai\'} <div class="video w240" id="swf_cover_{bid}_{i}"> <div class="video_bg"> <div class="video_song">{m.title}</div> <div class="video_name">{m.author}</div> <a href="javascript:" onclick="load_swf(\'yinyuetai\',{bid},{i},\'{m.title}\',\'{m.pid}\')"> <div class="video_play"></div><img src="index.php?c=blog&a=getyytimg&src={m.img}" / alt="请问如何在内容模板中写标题和内容呢" > </a> </div> </div> <div style="max-width:90%" id="swf_play_{bid}_{i}"></div> {/if} {/each} {/if} {if body} <div class="text_area"> <p>{body}</p> </div> {/if} </div>');