原網站:http://bbs.phpcms.cn/thread-879943-1-1.html
簡介: 用phpcms做網站的時候,有些地方要用到推薦位列表,如幻燈片,特別推薦等。有時候因為文章的重要性問題,希望文章能夠按照后臺設置的排序號來排序。但是,phpcms這里卻不好使了
用phpcms做網站的時候,有些地方要用到推薦位列表,如幻燈片,特別推薦等。有時候因為文章的重要性問題,我希望文章能夠按照后臺設置的排序號來排序。這時代碼應該是:
{pc:content action="position" posid="1" order="listorder DESC" num="3"} {loop $data $r} html code {/loop} {/pc}
其中order="listorder DESC"就是按照手工排序的意思。但是會發現,order="listorder DESC"效果和order="id DESC"一樣,實際上沒有排序降序功能,只能是ID降序或ID升序。
打開數據庫查看v9_position_data表,結果你會發現,表中listorder字段跟id是一樣的。
最后才找到解決的辦法。
1.打開文件:/phpcms/modules/admin/classes/push_api.class.php
找到:
$info['id'] = $info['listorder'] = $d['id'];
就是這一句,當添加文章或者修改文章的時候,把listorder變得跟id一樣,以至于,listorder排序不起作用。
所以上面那句代碼應該改為:
$info['id'] = $d['id'];
這樣一來添加文章或者修改文章的時候就不會改動listorder的值了。但單單這樣還不行,因為推薦標簽在取數據的時候,是根據v9_position_data表的listorder來排序的,但后臺更新文章排序的時候,并沒有更新v9_position_data這個表的listorder,所以得加上這個功能。
2.打開文件:/phpcms/modules/content/content.php
找到:
foreach($_POST['listorders'] as $id => $listorder) { $this->db->update(array('listorder'=>$listorder),array('id'=>$id)); }
在上面的后面加上(注意是在后邊加上這段代碼,不要修改上邊的代碼)
//更改推薦位排序開始 $this->db_config = pc_base::load_config('database'); $tablepre = $this->db_config['default']['tablepre']; $this->db->table_name = $tablepre."position_data"; foreach($_POST['listorders'] as $id => $listorder) { $r = $this->db->get_one(array('id'=>$id)); if($r['posid']){ $this->db->update(array('listorder'=>$listorder),array('id'=>$id,modelid=>$modelid)); } } //更改推薦位排序開始
改完這兩個地方就可以正常的使用了。
文章列表