给江湖家居至尊版的效果图翻页中,点击到最后一张图时,会自动返回到第一张效果图,现改为点击到最后一张图,地址栏中自动跳转到下一套效果图,这样用户在看效果图时,就不需要关闭当前窗口,可以直接看到下一套效果图。
实现方法:
一、打开 \system\home\controllers\case.ctl.php 控制器文件,查找 "detail" 对象方法,在相应位置插入如下两行代码:
$pager['prev'] = K::M('case/case')->up_detail($case_id);
$pager['next'] = K::M('case/case')->next_detail($case_id);
修改后代码如下:
public function detail($case_id, $page = 1)
{
$case = $this->check_case($case_id);
K::M('case/case')->update_count($case_id, 'views', 1);
if($company_id = $case['company_id']){
$this->pagedata['company'] = K::M('company/company')->detail($case['company_id']);
}else if($member = K::M('member/member')->member($case['uid'])){
if($member['from'] == 'gz'){
$this->pagedata['gz'] = K::M('gz/gz')->detail($case['uid']);
}else if($member['from'] == 'designer'){
$this->pagedata['designer'] = K::M('designer/designer')->detail($case['uid']);
}
}
if($attr_values = K::M('case/attr')->attrs_by_case($case_id)){
foreach($attr_values as $k=>$v){
$case['attrvalues'][$k] = $v['attr_value_id'];
}
}
$this->pagedata['photos'] = K::M('case/photo')->items_by_case($case_id, 1, 50);
$filter = $pager = array();
$pager['prev'] = K::M('case/case')->up_detail($case_id);
$pager['next'] = K::M('case/case')->next_detail($case_id);
$pager['page'] = max(intval($page), 1);
$pager['limit'] = $limit = 5;
$filter['case_id'] = $case_id;
if ($items = K::M('case/comment')->items($filter,array('dateline'=>'desc'), $page, $limit, $count)) {
$pager['count'] = $count;
$pager['pagebar'] = $this->mkpage($count, $limit, $page, $this->mklink('case:detail', array($case_id,'{page}')));
$uids = array();
foreach ($items as $k => $v) {
$uids[$v['uid']] = $v['uid'];
}
if($uids){
$this->pagedata['user_list'] = K::M('member/member')->items_by_ids($uids);
}
$this->pagedata['items'] = $items;
}
$access = $this->system->config->get('access');
$this->pagedata['comment_yz'] = $access['verifycode']['comment'];
$this->pagedata['detail'] = $case;
$this->pagedata['pager'] = $pager;
$this->pagedata['mobile_url'] = $this->mklink('mobile/case:detail', array($case_id));
$this->seo->init('case_detail',array(
'title' => $case['title'],
'home_name'=>$detail['home_name'],
'seo_title' => $case['seo_title'],
'seo_keywords' => $case['seo_keywords'],
'seo_description' => $case['seo_description'],
));
$this->tmpl = 'case/detail.html';
}
二、再打开 \system\models\case\case.mdl.php 数据库模型文件,查找 "up_detail" 和 "next_detail" 对象方法中的$sql 变量,相应代码如下:
$sql = "SELECT * FROM ".$this->table($this->_table)." WHERE $where ORDER BY ".$this->_pk." DESC LIMIT 1";
$sql = "SELECT * FROM ".$this->table($this->_table)." WHERE $where ORDER BY ".$this->_pk." ASC LIMIT 1";
在这两句代码中分别添加 “AND closed=0”查询条件, 修改后代码如下:
$sql = "SELECT * FROM ".$this->table($this->_table)." WHERE $where AND closed=0 ORDER BY ".$this->_pk." DESC LIMIT 1";
$sql = "SELECT * FROM ".$this->table($this->_table)." WHERE $where AND closed=0 ORDER BY ".$this->_pk." ASC LIMIT 1";
三、接下来在\themes\default\case\detail.html 模板文件中适当位置调用如下变量标签就行了,以下为调用示例:
<a href="detail-<{$pager.prev.case_id}>.html">上一套效果图:<{$pager.prev.title}></a>
<a href="detail-<{$pager.next.case_id}>.html">下一套效果图:<{$pager.next.title}></a>
|
|