商品列表页每个商品下调用最新评论增加用户体验

2016-07-07 14:55 来源:www.chinab4c.com 作者:ecshop专家



这里只讲原理,关于如何css美化,大家自己做就行了.

图片附件加不上,这是为什么?


演示图:

鼠标滑过商品,下方显示最新评论;



无评论时不显示内容;



首先打开根目录 category.php

大约 447-455行之间

  1. /* 获得商品列表 */
  2. $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, ' .
  3. "IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, g.promote_price, g.goods_type, " .
  4. 'g.promote_start_date, g.promote_end_date, g.goods_brief, g.goods_thumb , g.goods_img ' .
  5. 'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' .
  6. 'LEFT JOIN ' . $GLOBALS['ecs']->table('member_price') . ' AS mp ' .
  7. "ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' " .
  8. "WHERE $where $ext ORDER BY $sort $order";
  9. $res = $GLOBALS['db']->selectLimit($sql, $size, ($page - 1) * $size);
复制代码


替换为:

  1. /* 获得商品列表 */
  2. $sql = 'SELECT g.goods_id,c.id_value,c.user_name,c.content, 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, ' .
  3. "IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, g.promote_price, g.goods_type, " .
  4. 'g.promote_start_date, g.promote_end_date, g.goods_brief, g.goods_thumb , g.goods_img ' .
  5. 'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' .
  6. 'LEFT JOIN ' . $GLOBALS['ecs']->table('comment') . ' AS c ON c.id_value = g.goods_id ' .
  7. 'LEFT JOIN ' . $GLOBALS['ecs']->table('member_price') . ' AS mp '.
  8. "ONmp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' " .
  9. "WHERE $where $ext ORDER BY $sort $order";
  10. $res = $GLOBALS['db']->selectLimit($sql, $size, ($page - 1) * $size);
复制代码


然后搜索如下代码:

  1. $arr[$row['goods_id']]['name'] = $row['goods_name'];
复制代码


在其下方添加:

  1. $arr[$row['goods_id']]['uname'] = $row['user_name'];
  2. $arr[$row['goods_id']]['ucon'] = $row['content'];
复制代码


然后打开:根目录/thmes/你的模板/library/goods_list.lib

如果你用的默认模板请搜索:

  1. <a href="javascript:;" id="compareLink" onClick="Compare.add({$goods.goods_id},'{$goods.goods_name|escape:"html"}','{$goods.type}')" class="f6">{$lang.compare}</a>
复制代码


在其下方添加如下代码:

  1. <!--{if $goods.uname neq ''}--><p class="rl cl"><em>{$goods.uname}:</em>{$goods.ucon|truncate:26:""}</p><!--{/if}-->
复制代码


如果不是默认模板请自行查看单个商品循环列表中布局位置.


此时就完成了列表页商品下方的最新评论,只调用1条最新评论.

本文由 进口毛线 www.chinazhongrong.com 原创转载请注明.

回答:
谢谢,学习了