建站帮助

诚信合作, 高质专业!

Phpcms V9内容模型列表标签where条件失效的修改方法

2018-07-23 21:55:00 浏览 我要评论

最近忙于项目,碰到一个问题:在使用action="lists"调用内容模型的数据列表时,如果加上where条件语句,会造成其他条件失效,今天CMSYOU就列表标签where条件失效问题与大家分享修正方法。

比如调用语句:

{pc:content action="lists" catid="$catid" where="posids`!='0'"num="10" order="id DESC" page="$page"}
        <ul>
{loop $data $r}
<li><span>{date('Y-m-d H:i:s',$r[inputtime])}</span>·<a href="{$r[url]}" target="_blank"{title_style($r[style])}>{$r[title]}</a></li>
{/loop}
        </ul>
        <div class="pagenavi">{$pages}</div>
{/pc}
上面的action="lists"调用语句里边出现了 where="posids`!='0'",于是造成其他条件失效。
通过查找源头php写法,找到/phpcms/modules/content/classes/content_tag.class.php文件,具体修改如下:
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;
}
}

希望大家抱着研究的心态自定义phpcms,多多分享,如果有好的文章也欢迎投稿,投稿email:info@cmsyou.com。

同时欢迎大家收听CMSYOU官方微博,相互探讨Phpcms

我要收藏
点个赞吧

相关阅读

本月热门

精选推荐

在线客服

扫一扫,关注我们

扫一扫,关注我们