精品人人槡人妻人人槡,无码午夜国产视频,日韩精品无码有码视频,国产成人精品日本亚洲成熟

<var id="lf53i"><track id="lf53i"><ins id="lf53i"></ins></track></var>

  • <rp id="lf53i"></rp>
    <var id="lf53i"><track id="lf53i"><ins id="lf53i"></ins></track></var>

    <video id="lf53i"></video>
    <b id="lf53i"><acronym id="lf53i"></acronym></b>

      1. 0712-2888027 189-8648-0214
        微信公眾號

        孝感風信網(wǎng)絡科技有限公司微信公眾號

        當前位置:主頁 > 技術支持 > PHPCMS > phpcms v9關聯(lián)文章排序陳舊問題怎么修改

        phpcms v9關聯(lián)文章排序陳舊問題怎么修改

        時間:2015-11-09來源:風信官網(wǎng) 點擊: 873次

        phpcms v9中相關閱讀的排序問題,調(diào)用出來的內(nèi)容十分陳舊。于是嘗試添加 order="id DESC" 參數(shù)進行排序,調(diào)用順序依然毫無變化。打開 phpcms/modules/content/classes/content_tag.class.php 內(nèi)容模型標簽類一看,發(fā)現(xiàn)該標簽僅在內(nèi)容存在人為設置的相關閱讀時,才依照order參數(shù)進行排序。而當內(nèi)容不存在人為設置的相關閱讀時,則按照關鍵字進 行查詢,但此時并沒有按照order參數(shù)進行排序。而是不進行排序。這也就是為什么文章調(diào)用的相關閱讀總是那么陳舊的原因了。

        修正該問題的方法:
        修改 phpcms/modules/content/classes/content_tag.class.php 內(nèi)容模型標簽類文件,將 content_tag 類中 relation 方法修改為:

        /**
        * 相關文章標簽
        * @param $data
        */
        public function relation($data) {
        $catid = intval($data['catid']);
        if(!$this->set_modelid($catid)) return false;
        $order = $data['order'];
        $sql = "`status`=99";
        $limit = $data['id'] ? $data['limit']+1 : $data['limit'];
        if($data['relation']) {
        $relations = explode('|',trim($data['relation'],'|'));
        $relations = array_diff($relations, array(null));
        $relations = implode(',',$relations);
        $sql = " `id` IN ($relations)";
        $key_array = $this->db->select($sql, '*', $limit, $order,'','id');
        } elseif($data['keywords']) {
        $keywords = str_replace('%', '',$data['keywords']);
        $keywords_arr = explode(' ',$keywords);
        $key_array = array();
        $number = 0;
        $i =1;
        foreach ($keywords_arr as $_k) {
        $sql2 = $sql." AND `keywords` LIKE '%$_k%'".(isset($data['id']) && intval($data['id']) ? " AND `id` != '".abs(intval($data['id']))."'" : '');
        $r = $this->db->select($sql2, '*', $limit, $order,'','id');
        $number += count($r);
        foreach ($r as $id=>$v) {
        if($i<= $data['limit'] && !in_array($id, $key_array)) $key_array[$id] = $v;
        $i++;
        }
        if($data['limit']<$number) break;
        }
        }
        if($data['id']) unset($key_array[$data['id']]);
        return $key_array;
        }

        其 實只是將 $r = $this->db->select($sql2, '*', $limit, '','','id'); 替換為了 $r = $this->db->select($sql2, '*', $limit, $order,'','id'); 讓order參數(shù)傳入查詢方法。
        在模板當中,使用如下標簽,加上order參數(shù)即可實現(xiàn)排序了。

        {pc:content action="relation" relation="$relation" id="$id" catid="$catid" num="5" keywords="$rs[keywords]" order="id DESC"}
        {loop $data $r}
        {/loop}
        {/pc}

        如果有潔癖的朋友,擔心直接修改PC會影響未來升級,可以將其單獨提取出來。放到模板中當作函數(shù)使用。代碼如下:

        <?php
        /**
        * 內(nèi)容模型 - 相關文章標簽(修正排序異常問題)
        * @param $data
        */
        function mk1_content_tag_relation($data) {
        $db = pc_base::load_model('content_model');
        $catid = intval($data['catid']);
        $siteids = getcache('category_content','commons');
        if(!$siteids[$catid]) return false;
        $siteid = $siteids[$catid];
        $category = getcache('category_content_'.$siteid,'commons');
        if(empty($category)) return false;
        if($category[$catid]['type']!=0) return false;
        $db->set_model($category[$catid]['modelid']);
        $order = $data['order'];
        $sql = "`status`=99";
        $limit = $data['id'] ? $data['limit']+1 : $data['limit'];
        if($data['relation']) {
        $relations = explode('|',trim($data['relation'],'|'));
        $relations = array_diff($relations, array(null));
        $relations = implode(',',$relations);
        $sql = " `id` IN ($relations)";
        $key_array = $db->select($sql, '*', $limit, $order,'','id');
        } elseif($data['keywords']) {
        $keywords = str_replace('%', '',$data['keywords']);
        $keywords_arr = explode(' ',$keywords);
        $key_array = array();
        $number = 0;
        $i =1;
        foreach ($keywords_arr as $_k) {
        $sql2 = $sql." AND `keywords` LIKE '%$_k%'".(isset($data['id']) && intval($data['id']) ? " AND `id` != '".abs(intval($data['id']))."'" : '');
        $r = $db->select($sql2, '*', $limit, $order,'','id');
        $number += count($r);
        foreach ($r as $id=>$v) {
        if($i<= $data['limit'] && !in_array($id, $key_array)) $key_array[$id] = $v;
        $i++;
        }
        if($data['limit']<$number) break;
        }
        }
        if($data['id']) unset($key_array[$data['id']]);
        return $key_array;
        }
        ?>

        當前位置:腳本學堂 > 網(wǎng)頁教程 > phpcms > 正文

        phpcms v9關聯(lián)文章排序陳舊問題怎么修改
        發(fā)布時間:2014-05-03編輯:kksky

        本文介紹了phpcms v9關聯(lián)文章排序陳舊問題的修改方法,phpcms v9中相關閱讀的排序問題,調(diào)用出來的內(nèi)容十分陳舊,有需要的朋友參考學習下。

        phpcms v9中相關閱讀的排序問題,調(diào)用出來的內(nèi)容十分陳舊。于是嘗試添加 order="id DESC" 參數(shù)進行排序,調(diào)用順序依然毫無變化。打開 phpcms/modules/content/classes/content_tag.class.php 內(nèi)容模型標簽類一看,發(fā)現(xiàn)該標簽僅在內(nèi)容存在人為設置的相關閱讀時,才依照order參數(shù)進行排序。而當內(nèi)容不存在人為設置的相關閱讀時,則按照關鍵字進 行查詢,但此時并沒有按照order參數(shù)進行排序。而是不進行排序。這也就是為什么文章調(diào)用的相關閱讀總是那么陳舊的原因了。

        修正該問題的方法:
        修改 phpcms/modules/content/classes/content_tag.class.php 內(nèi)容模型標簽類文件,將 content_tag 類中 relation 方法修改為:

        復制代碼 代碼示例:
        /**
        * 相關文章標簽
        * @param $data
        */
        public function relation($data) {
        $catid = intval($data['catid']);
        if(!$this->set_modelid($catid)) return false;
        $order = $data['order'];
        $sql = "`status`=99";
        $limit = $data['id'] ? $data['limit']+1 : $data['limit'];
        if($data['relation']) {
        $relations = explode('|',trim($data['relation'],'|'));
        $relations = array_diff($relations, array(null));
        $relations = implode(',',$relations);
        $sql = " `id` IN ($relations)";
        $key_array = $this->db->select($sql, '*', $limit, $order,'','id');
        } elseif($data['keywords']) {
        $keywords = str_replace('%', '',$data['keywords']);
        $keywords_arr = explode(' ',$keywords);
        $key_array = array();
        $number = 0;
        $i =1;
        foreach ($keywords_arr as $_k) {
        $sql2 = $sql." AND `keywords` LIKE '%$_k%'".(isset($data['id']) && intval($data['id']) ? " AND `id` != '".abs(intval($data['id']))."'" : '');
        $r = $this->db->select($sql2, '*', $limit, $order,'','id');
        $number += count($r);
        foreach ($r as $id=>$v) {
        if($i<= $data['limit'] && !in_array($id, $key_array)) $key_array[$id] = $v;
        $i++;
        }
        if($data['limit']<$number) break;
        }
        }
        if($data['id']) unset($key_array[$data['id']]);
        return $key_array;
        }

        其 實只是將 $r = $this->db->select($sql2, '*', $limit, '','','id'); 替換為了 $r = $this->db->select($sql2, '*', $limit, $order,'','id'); 讓order參數(shù)傳入查詢方法。
        在模板當中,使用如下標簽,加上order參數(shù)即可實現(xiàn)排序了。

        復制代碼 代碼示例:
        {pc:content action="relation" relation="$relation" id="$id" catid="$catid" num="5" keywords="$rs[keywords]" order="id DESC"}
        {loop $data $r}
        {/loop}
        {/pc}

        如果有潔癖的朋友,擔心直接修改PC會影響未來升級,可以將其單獨提取出來。放到模板中當作函數(shù)使用。代碼如下:

        復制代碼 代碼示例:
        <?php
        /**
        * 內(nèi)容模型 - 相關文章標簽(修正排序異常問題)
        * @param $data
        */
        function mk1_content_tag_relation($data) {
        $db = pc_base::load_model('content_model');
        $catid = intval($data['catid']);
        $siteids = getcache('category_content','commons');
        if(!$siteids[$catid]) return false;
        $siteid = $siteids[$catid];
        $category = getcache('category_content_'.$siteid,'commons');
        if(empty($category)) return false;
        if($category[$catid]['type']!=0) return false;
        $db->set_model($category[$catid]['modelid']);
        $order = $data['order'];
        $sql = "`status`=99";
        $limit = $data['id'] ? $data['limit']+1 : $data['limit'];
        if($data['relation']) {
        $relations = explode('|',trim($data['relation'],'|'));
        $relations = array_diff($relations, array(null));
        $relations = implode(',',$relations);
        $sql = " `id` IN ($relations)";
        $key_array = $db->select($sql, '*', $limit, $order,'','id');
        } elseif($data['keywords']) {
        $keywords = str_replace('%', '',$data['keywords']);
        $keywords_arr = explode(' ',$keywords);
        $key_array = array();
        $number = 0;
        $i =1;
        foreach ($keywords_arr as $_k) {
        $sql2 = $sql." AND `keywords` LIKE '%$_k%'".(isset($data['id']) && intval($data['id']) ? " AND `id` != '".abs(intval($data['id']))."'" : '');
        $r = $db->select($sql2, '*', $limit, $order,'','id');
        $number += count($r);
        foreach ($r as $id=>$v) {
        if($i<= $data['limit'] && !in_array($id, $key_array)) $key_array[$id] = $v;
        $i++;
        }
        if($data['limit']<$number) break;
        }
        }
        if($data['id']) unset($key_array[$data['id']]);
        return $key_array;
        }
        ?>

        在模板中,使用如下PHP代碼獲取即可。

        {php $data = mk1_content_tag_relation(array('relation'=>$relation,'id'=>$id,'catid'=>$catid,'keywords'=>$rs['keywords'],'order'=>'id DESC','limit'=>'4')); }
        {loop $data $r}
        {/loop}

        其實只是一個小問題,PC在未來應該會進行修正的,以上方法提供給那些心急的站長朋友們。

        欄目列表
        推薦內(nèi)容
        熱點內(nèi)容
        展開