在之前的文章:PhpCms V9多栏目文章标签调用及当前页网址获取、PhpCms V9多栏目文章数据调用方法(二)中,讲解中PC v9调用多个栏目数据的方法,最近偶然发现一个Phpcms v9多栏目文章数据调用的方法,CMSYOU特别分享在此!
具体思路是对content_tag.class.php的调用函数进行修改,达到方便快捷的调用方式:
{pc:content action="lists" catid="1,2,3" order="id DESC" num="10"}<ul>{loop $data $key $val}<li><a href="{$val[url]}">{$val[title]}</a></li>{/loop}</ul>{/pc}
具体Phpcms v9多栏目文章数据调用的修改方法:
修改phpcms/modules/content/classes/content_tag.class.php文件,修改第61-75行:
$catid = intval($data['catid']);
if(!$this->set_modelid($catid)) return false;
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;
}
}
修改为:
$arr_catid = explode(',',$data['catid']);
if(isset($data['where'])) {
$sql = $data['where'];
} else {
$thumb = intval($data['thumb']) ? " AND thumb != ''" : '';
if(count($arr_catid) > 1){
$val_arr = array();
foreach($arr_catid as $key => $val){
$str_catid = intval($val);
if(!$this->set_modelid($str_catid)) return false;
if($this->category[$val]['child']) {
$catids_str = $this->category[$val]['arrchildid'];
$pos = strpos($catids_str,',')+1;
$val_arr[] = substr($catids_str, $pos);
} else {
$val_arr[] = $val;
}
}
$imcatid = implode (",",$val_arr);
$sql = "status=99 AND catid IN ($imcatid)".$thumb;
}else{
$catid = $arr_catid[0];
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!
点击加载更多