phpcms關(guān)聯(lián)文章排序不變怎么辦?

phpcms關(guān)聯(lián)文章排序不變怎么辦?

phpcms排序不變怎么辦?

phpcms關(guān)聯(lián)文章排序不變問題的修改方法:

打開 phpcms/modules/content/classes/content_tag.class.php 內(nèi)容模型標簽類,發(fā)現(xiàn)該標簽僅在內(nèi)容存在人為設置的相關(guān)閱讀時,則依照order參數(shù)進行排序。而當內(nèi)容不存在人為設置的相關(guān)閱讀時,則按照關(guān)鍵字進行查詢,但此時并沒有按照order參數(shù)進行排序。而是不進行排序。這也就是為什么文章調(diào)用的相關(guān)閱讀總是那么陳舊的原因了。

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

代碼如下:

/** *?相關(guān)文章標簽 *?@param?$data */ public?function?relation($data)?{ $catid?=?intval($data['catid']); if(!$this-&gt;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-&gt;db-&gt;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'])?&amp;&amp;?intval($data['id'])???"?AND?`id`?!=?'".abs(intval($data['id']))."'"?:?''); $r?=?$this-&gt;db-&gt;select($sql2,?'*',?$limit,?$order,'','id'); $number?+=?count($r); foreach?($r?as?$id=&gt;$v)?{ if($i<p>其實只是將 $r = $this-&gt;db-&gt;select($sql2, '*', $limit, '','','id'); 替換為了 $r = $this-&gt;db-&gt;select($sql2, '*', $limit, $order,'','id'); 讓order參數(shù)傳入查詢方法。<br>在模板當中,使用如下標簽,加上order參數(shù)即可實現(xiàn)排序了。<br></p><p><span>立即學習</span>“<a href="https://pan.quark.cn/s/7fc7563c4182" style="text-decoration: underline !!important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">PHP免費學習筆記(深入)</a>”;</p><p>代碼如下:</p><pre class="brush:php;toolbar:false">{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)容模型 - 相關(guān)文章標簽(修正排序異常問題) * @param $data */ function mk1_content_tag_relation($data) { $db = pc_base::load_model(&#39;content_model&#39;); $catid = intval($data[&#39;catid&#39;]); $siteids = getcache(&#39;category_content&#39;,&#39;commons&#39;); if(!$siteids[$catid]) return false; $siteid = $siteids[$catid]; $category = getcache(&#39;category_content_&#39;.$siteid,&#39;commons&#39;); if(empty($category)) return false; if($category[$catid][&#39;type&#39;]!=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-&gt;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'])?&amp;&amp;?intval($data['id'])???"?AND?`id`?!=?'".abs(intval($data['id']))."'"?:?''); $r?=?$db-&gt;select($sql2,?'*',?$limit,?$order,'','id'); $number?+=?count($r); foreach?($r?as?$id=&gt;$v)?{ if($i

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

代碼如下:

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

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

推薦教程:《PHP視頻教程

? 版權(quán)聲明
THE END
喜歡就支持一下吧
點贊8 分享