ECSHOP商品列表页显示每个商品的评论等级和评论数量
时间:2024年02月04日
/来源:网络
/编辑:佚名
第一步:首先修改category.php 文件,定位到 category_get_goods() 函数部分
找到
$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";
将之修改为
$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, " .
" IFNULL(AVG(r.comment_rank),0) AS comment_rank,IF(r.comment_rank,count(*),0) AS comment_count, ".
'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]' " .
' LEFT JOIN '. $GLOBALS['ecs']->table('comment') .' AS r '.
'ON r.id_value = g.goods_id AND comment_type = 0 AND r.parent_id = 0 AND r.status = 1 ' .
"WHERE $where $ext group by g.goods_id ORDER BY $sort $order";
然后继续找到
$arr[$row['goods_id']]['url'] = build_uri('goods', array('gid'=>$row['goods_id']), $row['goods_name']);
在它下面增加几行代码
$row['comment_rank'] = ceil($row['comment_rank']) == 0 ? 5 : ceil($row['comment_rank']);
$arr[$row['goods_id']]['comment_rank']=$row['comment_rank'];
$arr[$row['goods_id']]['comment_count']=$row['comment_count'];
第二步(以官方默认模板为例):
修改 htemes/default/library/goods_list.lbi 文件
找到
<a href="javascript:collect({$goods.goods_id});" class="f6">{$lang.btn_collect}</a>
在它上面增加
<img src="images/stars{$goods.comment_rank}.gif" style="width:78px;height:15px;" /><br>
评论数:{$goods.comment_count}<br>
ECSHOP系统有缓存机制,如果某个商品有了新的评论,列表页的评论数量不会立马随着更新。得等到下次更新缓存的时候才会更新。
如果您想列表页能即时体现评论数量的变化。只需继续进行下面修改即可
------------------------------------------------------------------------------------------------
把 category.php 文件的
$smarty->caching = true;
修改为
$smarty->caching = false;
-----------------------------------------------------------------------------------------------
找到
$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";
将之修改为
$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, " .
" IFNULL(AVG(r.comment_rank),0) AS comment_rank,IF(r.comment_rank,count(*),0) AS comment_count, ".
'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]' " .
' LEFT JOIN '. $GLOBALS['ecs']->table('comment') .' AS r '.
'ON r.id_value = g.goods_id AND comment_type = 0 AND r.parent_id = 0 AND r.status = 1 ' .
"WHERE $where $ext group by g.goods_id ORDER BY $sort $order";
然后继续找到
$arr[$row['goods_id']]['url'] = build_uri('goods', array('gid'=>$row['goods_id']), $row['goods_name']);
在它下面增加几行代码
$row['comment_rank'] = ceil($row['comment_rank']) == 0 ? 5 : ceil($row['comment_rank']);
$arr[$row['goods_id']]['comment_rank']=$row['comment_rank'];
$arr[$row['goods_id']]['comment_count']=$row['comment_count'];
第二步(以官方默认模板为例):
修改 htemes/default/library/goods_list.lbi 文件
找到
<a href="javascript:collect({$goods.goods_id});" class="f6">{$lang.btn_collect}</a>
在它上面增加
<img src="images/stars{$goods.comment_rank}.gif" style="width:78px;height:15px;" /><br>
评论数:{$goods.comment_count}<br>
ECSHOP系统有缓存机制,如果某个商品有了新的评论,列表页的评论数量不会立马随着更新。得等到下次更新缓存的时候才会更新。
如果您想列表页能即时体现评论数量的变化。只需继续进行下面修改即可
------------------------------------------------------------------------------------------------
把 category.php 文件的
$smarty->caching = true;
修改为
$smarty->caching = false;
-----------------------------------------------------------------------------------------------
新闻资讯 更多
热门文章
- 178Moban源码谈谈免费源码与收费源码的区别
- 2帝国CMS忘记后台登陆用户名、密码、认证码的解决方法
- 3帝国CMS(EmpireCMS) v7.5后台任意代码执行漏洞及具体修复方法
- 4帝国CMS和WordPress 哪个好?哪个适合建站?
- 5如何解决Discuz的密码错误次数过多请15分钟后登陆的问题
- 6帝国cms灵动标签取得内容和栏目链接地址
- 7emlog pro 注册码“开心”教程(如果有一天,emlog官方版 或者 emlog免费版 跑路了,那用户怎么办?)
- 8织梦CMS在nginx下设置伪静态方法(附nginx伪静态规则)
- 9帝国cms后台登录出现”您还未登录”怎么解决?
- 10帝国cms7.5忘记登录密码 和忘记登录认证码以及多次登录 失败被锁定解决办法