ecshop 同一个广告位发布多则广告的排序问题

ecshop很强大,这是毋庸置疑的!

但是在添加广告位的时候,如果单一的广告位,里面有多则广告,ecshop是让其随机显示广告内容,并且后台没有更改的选项.

如果我要根据ID或者其他字段来排序,那应该怎么处理呢?

其实也很简单

 

修改includes/lib_insert.php文件

找到这句代码

if (!empty($arr[‘num’]) && $arr[‘num’] != 1)

然后,找到下面的

  1. if (!empty($arr['num']) && $arr['num'] != 1)
  2. {
  3. $sql = 'SELECT a.ad_id, a.position_id, a.media_type, a.ad_link, a.ad_code, a.ad_name, p.ad_width, ' .
  4. 'p.ad_height, p.position_style, RAND() AS rnd ' .
  5. 'FROM ' . $GLOBALS['ecs']->table('ad') . ' AS a '.
  6. 'LEFT JOIN ' . $GLOBALS['ecs']->table('ad_position') . ' AS p ON a.position_id = p.position_id ' .
  7. "WHERE enabled = 1 AND start_time <= '" . $time . "' AND end_time >= '" . $time . "' ".
  8. "AND a.position_id = '" . $arr['id'] . "' " .
  9. 'ORDER BY rnd LIMIT ' . $arr['num'];
  10. $res = $GLOBALS['db']->GetAll($sql);
  11. }
  12. else
  13. {
  14. if ($static_res[$arr['id']] === NULL)
  15. {
  16. $sql = 'SELECT a.ad_id, a.position_id, a.media_type, a.ad_link, a.ad_code, a.ad_name, p.ad_width, '.
  17. 'p.ad_height, p.position_style, RAND() AS rnd ' .
  18. 'FROM ' . $GLOBALS['ecs']->table('ad') . ' AS a '.
  19. 'LEFT JOIN ' . $GLOBALS['ecs']->table('ad_position') . ' AS p ON a.position_id = p.position_id ' .
  20. "WHERE enabled = 1 AND a.position_id = '" . $arr['id'] .
  21. "' AND start_time <= '" . $time . "' AND end_time >= '" . $time . "' " .
  22. 'ORDER BY rnd LIMIT 1';
  23. $static_res[$arr['id']] = $GLOBALS['db']->GetAll($sql);
  24. }
  25. $res = $static_res[$arr['id']];
  26. }

 

看到了吗?这里有2个order by rnd,就是随机显示内容.

只要把rnd修改了就好了

例如我要按照广告ID倒序,那就把rnd改成”a.ad_id desc”

 

大功告成

发表评论