ECSHOP商城 分类产品页面如何实现随机显示
注:以下文章来源于:http://blog.sina.com.cn/s/blog_3e6eb9830100h2ml.html,正在弄一个商城产品的随机显示功能,要的首页推荐产品随机,缘分驱使找到了这个一篇分类页面的产品随机,保存下,以备后用。
针对大家的需求,经过研究开发,实现ecshop分类下随机显示商品,打破后台规定的按照上架时间,价格、等先后顺序排序,让很多人,上传完毕产品,第一页总是显示同类商品:
1、下载并备份你的根目录下的文件category.php文件
2、找到如下代码部分,大约在450行:
/* 获得商品列表 */
$sql = ‘SELECT g.goods_id, g.goods_name, g.goods_name_style, g.market_price, g.is_new, g.is_best, g.is_hot, g.shop_price AS org_price, ‘ .
“IFNULL(mp.user_price, g.shop_price * ‘$_SESSION[discount]’) AS shop_price, g.promote_price, g.goods_type, ” .
‘g.promote_start_date, g.promote_end_date, g.goods_brief, g.goods_thumb , g.goods_img ‘ .
‘FROM ‘ . $GLOBALS[‘ecs’]->table(‘goods’) . ‘ AS g ‘ .
‘LEFT JOIN ‘ . $GLOBALS[‘ecs’]->table(‘member_price’) . ‘ AS mp ‘ .
“ON mp.goods_id = g.goods_id AND mp.user_rank = ‘$_SESSION[user_rank]’ ” .
“WHERE $where $ext ORDER BY $sort $order”;替换为:
$zz=1;
$sql = ‘SELECT g.goods_id, g.goods_name, g.goods_name_style, g.market_price, g.is_new, g.is_best, g.is_hot, g.shop_price AS org_price, ‘ .
“IFNULL(mp.user_price, g.shop_price * ‘$_SESSION[discount]’) AS shop_price, g.promote_price, g.goods_type, ” .
‘g.promote_start_date, g.promote_end_date, g.goods_brief, g.goods_thumb , g.goods_img ‘ .
‘FROM ‘ . $GLOBALS[‘ecs’]->table(‘goods’) . ‘ AS g ‘ .
‘LEFT JOIN ‘ . $GLOBALS[‘ecs’]->table(‘member_price’) . ‘ AS mp ‘ .
“ON mp.goods_id = g.goods_id AND mp.user_rank = ‘$_SESSION[user_rank]’ ” .
“WHERE $where $ext”;
$sql .= $zz == 0 ? ” $order” : ” ORDER BY RAND()”;
即可实现分类下的产品随机显示了,但是前提是,到后台清空缓存来实现,不能每次刷新都随机,否则服务器会受不了的,这样就实现了和首页精品、新品、促销等栏目同样的功能。
通过清空缓存来实现产品的随机,随机显示竟然会占用服务器过多资源。学习了。
相关文章: