建站幫助

誠信合作, 高質專業!

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:[email protected]

同時歡迎大家收聽CMSYOU官方微博,相互探討Phpcms

我要收藏
點個贊吧
相關標簽:

相關閱讀

本月熱門

精選推薦

在線客服

掃一掃,關注我們

掃一掃,關注我們
金牌单双中特王