当前位置:Gxlcms > PHP教程 > 请问如何在内容模板中写标题和内容呢

请问如何在内容模板中写标题和内容呢

时间:2021-07-01 10:21:17 帮助过:14人阅读

这是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.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'],'

'),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} {$d.username} {/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 <1} {/if} {/each} {/if} {body}

    ');template('tmpl_model_2', ' {if attr.length > 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} ');

    人气教程排行