搜尋
首頁後端開發php教程请问如何在内容模板中写标题和内容呢

这是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="/static/imghwm/default1.png"  data-src="{avatar uid=$d.uid size=small}"  class="lazy"   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="/static/imghwm/default1.png"  data-src="{img}"  class="lazy"     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="/static/imghwm/default1.png"  data-src="{m.img}"  class="lazy"  / 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="/static/imghwm/default1.png"  data-src="{m.img}"  class="lazy"   / 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="/static/imghwm/default1.png"  data-src="index.php?c=blog&a=getyytimg&src={m.img}"  class="lazy"   / 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>');

陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
繼續使用PHP:耐力的原因繼續使用PHP:耐力的原因Apr 19, 2025 am 12:23 AM

PHP仍然流行的原因是其易用性、靈活性和強大的生態系統。 1)易用性和簡單語法使其成為初學者的首選。 2)與web開發緊密結合,處理HTTP請求和數據庫交互出色。 3)龐大的生態系統提供了豐富的工具和庫。 4)活躍的社區和開源性質使其適應新需求和技術趨勢。

PHP和Python:探索他們的相似性和差異PHP和Python:探索他們的相似性和差異Apr 19, 2025 am 12:21 AM

PHP和Python都是高層次的編程語言,廣泛應用於Web開發、數據處理和自動化任務。 1.PHP常用於構建動態網站和內容管理系統,而Python常用於構建Web框架和數據科學。 2.PHP使用echo輸出內容,Python使用print。 3.兩者都支持面向對象編程,但語法和關鍵字不同。 4.PHP支持弱類型轉換,Python則更嚴格。 5.PHP性能優化包括使用OPcache和異步編程,Python則使用cProfile和異步編程。

PHP和Python:解釋了不同的範例PHP和Python:解釋了不同的範例Apr 18, 2025 am 12:26 AM

PHP主要是過程式編程,但也支持面向對象編程(OOP);Python支持多種範式,包括OOP、函數式和過程式編程。 PHP適合web開發,Python適用於多種應用,如數據分析和機器學習。

PHP和Python:深入了解他們的歷史PHP和Python:深入了解他們的歷史Apr 18, 2025 am 12:25 AM

PHP起源於1994年,由RasmusLerdorf開發,最初用於跟踪網站訪問者,逐漸演變為服務器端腳本語言,廣泛應用於網頁開發。 Python由GuidovanRossum於1980年代末開發,1991年首次發布,強調代碼可讀性和簡潔性,適用於科學計算、數據分析等領域。

在PHP和Python之間進行選擇:指南在PHP和Python之間進行選擇:指南Apr 18, 2025 am 12:24 AM

PHP適合網頁開發和快速原型開發,Python適用於數據科學和機器學習。 1.PHP用於動態網頁開發,語法簡單,適合快速開發。 2.Python語法簡潔,適用於多領域,庫生態系統強大。

PHP和框架:現代化語言PHP和框架:現代化語言Apr 18, 2025 am 12:14 AM

PHP在現代化進程中仍然重要,因為它支持大量網站和應用,並通過框架適應開發需求。 1.PHP7提升了性能並引入了新功能。 2.現代框架如Laravel、Symfony和CodeIgniter簡化開發,提高代碼質量。 3.性能優化和最佳實踐進一步提升應用效率。

PHP的影響:網絡開發及以後PHP的影響:網絡開發及以後Apr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP類型提示如何起作用,包括標量類型,返回類型,聯合類型和無效類型?PHP類型提示如何起作用,包括標量類型,返回類型,聯合類型和無效類型?Apr 17, 2025 am 12:25 AM

PHP類型提示提升代碼質量和可讀性。 1)標量類型提示:自PHP7.0起,允許在函數參數中指定基本數據類型,如int、float等。 2)返回類型提示:確保函數返回值類型的一致性。 3)聯合類型提示:自PHP8.0起,允許在函數參數或返回值中指定多個類型。 4)可空類型提示:允許包含null值,處理可能返回空值的函數。

See all articles

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

AI Hentai Generator

AI Hentai Generator

免費產生 AI 無盡。

熱工具

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

強大的PHP整合開發環境

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

mPDF

mPDF

mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),

EditPlus 中文破解版

EditPlus 中文破解版

體積小,語法高亮,不支援程式碼提示功能

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具