A-A+
PHPCMS推荐位文章列表排序
这个功能很少用到,但还是研究了一下,一些比较重要的文章我们可以设置成为推荐文章,但有的时候推荐文章也需要进行排序,以重要的程序进行排序,最重要的放在前面,不太重要的放到后面。先来看一个PHPCMS中用到的简单的推荐位文章列表的代码:
{pc:content action="position" posid="2" order="listorder DESC" num="10"} {if $data} {loop $data $v} <li><a href="{$v['url']}">{$v['title']}</a></li> {/loop} {/if} {/pc}
在后台文章列表中我们可以进行文章的排序更改,这个字段是 listorder,如果不去更改,默认的全是 0 这样的排序,也就是正常的排序,上面代码中 posid="2" 意思就是把 listorder 为 2 的文章放到最前面,当我们运行的时候,却发现排序是无效的,打开 v9_position_data 的表,发现 listorder 字段值与 ID 是一样的,基本上已经可以确定 listorder 的值是着添加文章或修改文章而与 ID 值同步改变的。
要解决这个问题,打开文件:/phpcms/modules/admin/classes/push_api.class.php 文件,找到如下的代码:
$info['id'] = $info['listorder'] = $d['id'];
替换为
$info['id'] = $d['id'];
这样在在添加或修改文章的时候就不会再改动 listorder 的值了,排序列表的第一目标已经达到了,就是利用 listorder 来改变排序,但还差一步就是推荐标签在取数据的时候,是根据 v9_position_data 表的 listorder 来排序的,但后台更新文章排序的时候,并没有更新v9_position_data这个表的listorder,所以我们还要把这个功能加上。
打开文件 /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,m odelid=>$modelid)); } } //更改推荐位排序结束
PHPCMS推荐位文章列表按重量级排序基本上就是这样了,把刚开始贴出的文章运行一下看一下效果吧。