如何在php中写内容,请问如何在内容模板中写标题和内容呢
這是php文件,請問如何在內容模板中寫標題和內容呢?請大神給寫一個單條內容的模板。謝謝了,,由于代碼太長,我刪了一部份,急用,謝謝各位好心人了
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.domainFROM `".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.domainFROM `".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);}//獲取我關注的用戶feedsfunction followfeeds(){$followuid = spClass('db_follow')->getFollowUid($this->uid);if($followuid){$sql = "SELECT b. * , k.id AS likeid ,m.username,m.domainFROM `".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'],'
'),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個就任務moreif($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改成0if($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}
{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 attr.length >0} {each attr as img i} {if i <1}
{/if} {/each} {/if} {body}');template('tmpl_model_2', '
{if attr.length > 0} {each attr as m i} {if m.type == \'local\'}
{if m.title != \'null\' && m.author != \'null\'} {else} {/if} {/if} {if m.type == \'yinyuetai\'}
{m.title}
{m.author}
{/if} {/each} {/if} {if body}
{body} {/if}');
本文原創發布php中文網,轉載請注明出處,感謝您的尊重!
總結
以上是生活随笔為你收集整理的如何在php中写内容,请问如何在内容模板中写标题和内容呢的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 一个人自学会java有用吗,大连java
- 下一篇: mysql 20小时内,mysql中关于