1. 程式人生 > >修改phpcms v9關聯其他模型文章

修改phpcms v9關聯其他模型文章

一、首先找到\phpcms\modules\content\templates\relationlist.tpl.php
原始碼:

echo form::select_category('',$catid,'name="catid"',L('please_select_category'),$modelid,0,1);

修改成:

echo form::select_category('',$catid,'name="catid"',L('please_select_category'),13,0,1);

將$modelid改成想要關聯的模型數值;

二、首先找到\phpcms\modules\content\content.php
找到函式 function public_relationlist()
程式碼:

    /**
     * 相關文章選擇
     */
    public function public_relationlist() {
        pc_base::load_sys_class('format','',0);
        $show_header = '';
        $model_cache = getcache('model','commons');
        if(!isset($_GET['modelid'])) {
            showmessage(L('please_select_modelid'));
        } else
{ $page = intval($_GET['page']); 原://$modelid = intval($_GET['modelid']); 改://固定模型資訊 $remodelid=13;//填寫自己的要關聯模型的modelid $modelid = intval($remodelid); // $this->db->set_model($modelid); $where = ''; if
($_GET['catid']) { $catid = intval($_GET['catid']); $where .= "catid='$catid'"; } $where .= $where ? ' AND status=99' : 'status=99'; if(isset($_GET['keywords'])) { $keywords = trim($_GET['keywords']); $field = $_GET['field']; if(in_array($field, array('id','title','keywords','description'))) { if($field=='id') { $where .= " AND `id` ='$keywords'"; } else { $where .= " AND `$field` like '%$keywords%'"; } } } $infos = $this->db->listinfo($where,'',$page,12); $pages = $this->db->pages; include $this->admin_tpl('relationlist'); } }

三、找到 function public_getjson_ids()
程式碼:

    public function public_getjson_ids() {      
        $modelid = intval($_GET['modelid']);
        $id = intval($_GET['id']);
        $this->db->set_model($modelid);
        $tablename = $this->db->table_name;
        $this->db->table_name = $tablename.'_data';
        $r = $this->db->get_one(array('id'=>$id),'relation');
        if($r['relation']) {
            $relation = str_replace('|', ',', $r['relation']);
            $relation = trim($relation,',');
            $where = "id IN($relation)";
            $infos = array();
        原://$this->db->table_name = $tablename;
        改://連結資訊模型的表
            $newsmodelid=13;;//填寫自己的要關聯模型的modelid
            $this->newsdb = pc_base::load_model('content_model');
            $this->newsdb->set_model($newsmodelid); 
            //
            $datas = $this->newsdb->select($where,'id,title');
            foreach($datas as $_v) {
                $_v['sid'] = 'v'.$_v['id'];
                if(strtolower(CHARSET)=='gbk') $_v['title'] = iconv('gbk', 'utf-8', $_v['title']);
                $infos[] = $_v;
            }
            echo json_encode($infos);
        }
    }

效果圖:

這裡寫圖片描述
這裡寫圖片描述
這裡寫圖片描述

前臺程式碼呼叫:

{pc:get sql="SELECT * FROM wy_news_data  WHERE id=$id " cache="3600"   }  
 {loop $data1 $val}
    {pc:content action="relation" relation="$val[relation]" catid="26" num="12" } 
    {loop $data $r} 
            <li>
                <h2><span class="fcg mlr5 r"><i class="ico08"></i>{$r[catid]}{date('Y-m-d',$r[inputtime])}  </span><strong><i class="ico08"></i></strong><a target="_blank" title="{$r[title]}" href="{$r[url]}">{$r[title]}</a></h2>
                <p>{$r[description]}<a href="{$r[url]}">[檢視全文]</a></p>
            </li>          
    {/loop}
    {/pc}
{/loop}   
{/pc} 

有疑問的可以加群162092974諮詢