最近有看到朋友在ECSHOP論壇里提問: 如何在首頁增加一個類似于“銷售排行榜”的“瀏覽排行榜”,并且可以在后臺的“模板設(shè)置”里進(jìn)行控制。
由于系統(tǒng)默認(rèn)是沒有讀取瀏覽排行的,所以這部分功能既得增加程序,又得增加模板。
本教程是以 ecshop2.7.2 官方默認(rèn)模板 為例進(jìn)行講解的。
效果圖如下:

1)、將下面代碼復(fù)制并保存到 一個新文件中,文件路徑為: /themes/default/library/top10_click.lbi
2)、修改 /includes/lib_goods.php 文件
在最下面增加一個函數(shù)
/**
* 調(diào)用瀏覽排行榜
*
* @access public
* @return array
*/
function get_top10_click()
{
$sql="SELECT goods_id, goods_name, shop_price, goods_thumb " .
'FROM ' . $GLOBALS['ecs']->table('goods')." where is_on_sale = 1 AND is_alone_sale = 1 AND is_delete = 0 order by click_count desc limit 10";
$arr = $GLOBALS['db']->getAll($sql);
for ($i = 0, $count = count($arr); $i < $count; $i++)
{
$arr[$i]['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ?
sub_str($arr[$i]['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $arr[$i]['goods_name'];
$arr[$i]['url'] = build_uri('goods', array('gid' => $arr[$i]['goods_id']), $arr[$i]['goods_name']);
$arr[$i]['thumb'] = get_image_path($arr[$i]['goods_id'], $arr[$i]['goods_thumb'],true);
$arr[$i]['price'] = price_format($arr[$i]['shop_price']);
}
return $arr;
}
3)、修改 /index.php 文件
在 $smarty->assign('top_goods', get_top10()); // 銷售排行
下面另起一行增加 $smarty->assign('top_goods_click', get_top10_click()); // 瀏覽排行
修改模板文件 /themes/default/index.dwt
找到
在它的前面增加
4)、修改 /admin/includes/lib_template.php 文件
在 '/library/invoice_query.lbi' => 0,
上邊增加一行代碼
'/library/top10_click.lbi' => 0,
5)、繼續(xù)修改語言包文件 /languages/zh_cn/admin/template.php
在 $_LANG['template_libs']['top10'] = '銷售排行';
下邊增加一行代碼
$_LANG['template_libs']['top10_click'] = '瀏覽排行';
6)、修改 /themes/default/lib.xml 文件
找到
并且在它下面另起一行,增加
7)、最后進(jìn)入 后臺 》模板管理 》設(shè)置模板, 是不是看到了期待已久的“瀏覽排行”,設(shè)置一下,并清除緩存,就OK了
掃描二維碼手機(jī)查看該文章
文章引用:http://www.qingbaosc.com/news/webzhishi/153.html





