修改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咨询

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值