建站帮助

诚信合作, 高质专业!

Phpcms v9多栏目文章数据调用方法(三)

2019-01-10 15:58:45 浏览 我要评论

在之前的文章: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

我要收藏
点个赞吧
相关标签:

相关阅读

本月热门

精选推荐

在线客服

扫一扫,关注我们

扫一扫,关注我们