這篇文章主要介紹了在ECSHOP的商品列表調(diào)用評(píng)論數(shù)量的方法,需要的朋友可以參考下
ECSHOP的商品列表頁如果能顯示相對(duì)應(yīng)的評(píng)論數(shù),那就更好了,我們也可以添加一些瀏覽次數(shù),這樣商品的列表看起來就更加豐富了,今天我們就給大家來講解一下如何在ECSHOP的商品列表調(diào)用評(píng)論數(shù)量,需要修改系統(tǒng)文件,修改之前請(qǐng)備份相關(guān)文件,在ECSHOP的商品列表調(diào)用評(píng)論數(shù)量的方法
。修改分類文件
修改category.php 文件,定位到 category_get_goods() 函數(shù)部分找到
SQL Code復(fù)制內(nèi)容到剪貼板
$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 0 $order";
SQL Code復(fù)制內(nèi)容到剪貼板
$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 0 $order";
然后繼續(xù)找到
代碼如下:$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‘];
修改模版文件
修改 themes/default/library/goods_list.lbi 文件找到
代碼如下:{$lang.btn_collect}
在它上面增加
代碼如下:
評(píng)論數(shù):{$goods.comment_count}
PS:大家都知道ECSHOP系統(tǒng)有緩存機(jī)制,如果某個(gè)商品有了新的評(píng)論,列表頁的評(píng)論數(shù)量不會(huì)立馬隨著更新,
電腦資料
《在ECSHOP的商品列表調(diào)用評(píng)論數(shù)量的方法》(http://m.msguai.com)。得等到下次更新緩存的時(shí)候才會(huì)更新。如果您想列表頁能即時(shí)體現(xiàn)評(píng)論數(shù)量的變化。只需繼續(xù)進(jìn)行下面修改即可。
把 category.php 文件的
$smarty->caching = true;
修改為
$smarty->caching = false;