PHPCMS推荐位文章列表手动排序

来自:互联网
时间:2018-08-26
阅读:

一些比较重要的文章我们通常会设置为推荐,但是即使都是推荐的文章,也分重要程度的,如何把最重要的放到第一,把相对不重要的排序到后面呢?

首先来看下我写的推荐位文章列表代码:

{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}

我本意是希望推荐序号为2的文章,能够按照listorder这个字段来进行排序,也就是后台文章列表最左侧的排序的数字,但是不尽人意的是根本就是无效的。咱们只能去数据库一探究竟了!

打开数据库查看v9_position_data表,结果你会发现,表中listorder字段跟id是一样的。找到造成这种情况的原因,并解决问题。

打开文件:/phpcms/modules/admin/classes/push_api.class.php

大概在136行,找到:

$info['id'] = $info['listorder'] = $d['id'];

替换为:

$info['id'] = $d['id'];

这样一来添加文章或者修改文章的时候就不会改动listorder的值了。

但单单这样还不行,因为推荐标签在取数据的时候,是根据v9_position_data表的listorder来排序的,但后台更新文章排序的时候,并没有更新v9_position_data这个表的listorder,所以得加上这个功能。

打开文件:/phpcms/modules/content/content.php

大概在460行,找到:

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));
    }
   }
//更改推荐位排序结束

现在才算是完美的解决了,PHPCMS推荐位文章列表手动排序的问题。调用的代码我从一开始就写出来了,赶快动手实践一下吧!

返回顶部
顶部