{/pc}
一般网上都是到这一步就没有了,没有了......
但是你会发现,还有很多问题,下面就来解决
第一个问题:list条件下加入where后其他条件失效的问题
之前的一篇文章:解决lists标签中,加上where后其他条件失效的问题,其他条件失效了,如catid,thumb等等,也就是无法获取当前栏目的信息,而是把整个栏目下的所有文章都调用出来了!
打开/phpcms/modules/content/classes/目录下的content_tag.class.php这个文件,把下面的代码(大概第63行)
if(isset($data['where'])) {
$sql = $data['where'];
} else {
$thumb = intval($data['thumb']) ? " AND thumb != ''" : '';
if($this->category[$catid]['child']) {
$catids_str = $this->category[$catid]['arrchildid'];
$pos = strpos($catids_str,',')+1;
$catids_str = substr($catids_str, $pos);
$sql = "status=99 AND catid IN ($catids_str)".$thumb;
} else {
$sql = "status=99 AND catid='$catid'".$thumb;
}
}
替换为下面的代码即可。
if(isset($data['where'])) {
$where = (isset($data['where'])&&(!empty($data['where'])))?' AND '.$data['where']:'';
$thumb = intval($data['thumb']) ? " AND thumb != ''" : '';
if($this->category[$catid]['child']) {
$catids_str = $this->category[$catid]['arrchildid'];
$pos = strpos($catids_str,',')+1;
$catids_str = substr($catids_str, $pos);
$sql = "status=99".$where." AND catid IN ($catids_str)".$thumb;
} else {
$sql = "status=99".$where." AND catid='$catid'".$thumb;
}
} else {
$thumb = intval($data['thumb']) ? " AND thumb != ''" : '';
if($this->category[$catid]['child']) {
$catids_str = $this->category[$catid]['arrchildid'];
$pos = strpos($catids_str,',')+1;
$catids_str = substr($catids_str, $pos);
$sql = "status=99 AND catid IN ($catids_str)".$thumb;
} else {
$sql = "status=99 AND catid='$catid'".$thumb;
}
}
其实主要的修改思路是$where参数中并不包含当前栏目的id值,所以在$sql增加获取相关id的参数
第二个问题:分页数量不对
通过研究缓存得知,调用分页总数的函数是:
$content_total = $content_tag->count(array('catid'=>$catid,'where'=>$sql,'modelid'=>$modelid,'moreinfo'=>'1','limit'=>$offset.",".$pagesize,'action'=>'lists',));
通过这个,找到phpcms\modules\content\classes\content_tag.class.php大致36-56行,count函数如下:
public function count($data) {
if($data['action'] == 'lists') {
$catid = intval($data['catid']);
if(!$this->set_modelid($catid)) return false;
if(isset($data['where'])) {
$sql = $data['where'];
} else {
if($this->category[$catid]['child']) {
$catids_str = $this->category[$catid]['arrchildid'];
$pos = strpos($catids_str,',')+1;
$catids_str = substr($catids_str, $pos);
$sql = "status=99 AND catid IN ($catids_str)";
} else {
$sql = "status=99 AND catid='$catid'";
}
}
return $this->db->count($sql);
}
}
改为:
public function count($data) {
if($data['action'] == 'lists') {
$catid = intval($data['catid']);
$catids_str = $this->category[$catid]['arrchildid'];
if(!$this->set_modelid($catid)) return false;
if(isset($data['where'])) {
$sql = $data['where'];
if($this->category[$catid]['child']) {
$catids_str = $this->category[$catid]['arrchildid'];
$pos = strpos($catids_str,',')+1;
$catids_str = substr($catids_str, $pos);
$sql = $sql." AND catid IN ($catids_str)";
} else {
$sql = $sql." AND catid='$catid'";
}
} else {
if($this->category[$catid]['child']) {
$catids_str = $this->category[$catid]['arrchildid'];
$pos = strpos($catids_str,',')+1;
$catids_str = substr($catids_str, $pos);
$sql = "status=99 AND catid IN ($catids_str)";
} else {
$sql = "status=99 AND catid='$catid'";
}
}
return $this->db->count($sql);
}
}
你会发现,分页统计的修改原理仍然是$where条件下,没有传入当前栏目id这个参数!
大功告成,这样既然正常分页传参,也能正常获取当前栏目信息,获取的信息总数也正确了
但是,我并没有测试在get方式下,是不是有影响,欢迎大家测试!!!