最近有看到朋友在ECSHOP论坛里提问: 如何在首页增加一个类似于“销售排行榜”的“浏览排行榜”,并且可以在后台的“模板设置”里进行控制。( T/ q. v: Y6 k! ?, E; Z" I) ?! E: n
, s- J4 O3 ^) G3 m. h由于系统默认是没有读取浏览排行的,所以这部分功能既得增加程序,又得增加模板。, @* f- C3 S/ `3 ?6 o U
本教程是以 ecshop2.7.2 官方默认模板 为例进行讲解的。
h: e: s+ o. q
1 U& D/ k( ~9 k7 }效果图如下:
. e- q3 H" M" F( L3 R) \
- i9 p: `) v' c9 o- l2 |$ u3 |/ k
1)、将下面代码复制并保存到 一个新文件中,文件路径为: /themes/default/library/top10_click.lbi <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
' I0 Y. |& L8 M# D" y3 p7 }- L7 c<div class="box">
0 p5 X. V/ m: a8 Z; V4 Q <div class="box_2">
P/ ~5 b. @4 N# M+ N' z3 ? <h3><span>浏览排行</span></h3>8 B: q- i' V/ b9 C
<div class="top10List clearfix">
" L2 l9 `9 B" e \! \: o' J/ P P <!-- {foreach name=top_goods from=$top_goods_click item=goods}-->
( w) v" {1 H D; u% |) a$ t" w7 e% d+ N <ul class="clearfix">7 M& Q$ }+ J- t S
<img src="../images/top_{$smarty.foreach.top_goods.iteration}.gif" class="iteration" />" N5 F0 ?$ l+ S/ F
<!-- {if $smarty.foreach.top_goods.iteration<4}-->* _& o' k4 B! G, N& y
<li class="topimg">" \1 @1 B* U2 T7 o* R* u
<a href="{$goods.url}"><img src="{$goods.thumb}" alt="{$goods.name|escape:html}" class="samllimg" /></a>8 P! n+ n# ^; w4 D. a+ B! h* n
</li>
0 j C" R/ h' Z) K! y <!-- {/if} -->
" O7 ]$ Q1 w1 L q <li {if $smarty.foreach.top_goods.iteration<4}class="iteration1"{/if}>7 a$ E' Y( k. b
<a href="{$goods.url}" title="{$goods.name|escape:html}">{$goods.short_name}</a><br />
8 f+ R1 \9 `& R6 l; n. n5 Q {$lang.shop_price}<font class="f1">{$goods.price}</font><br />: M! k3 V5 G7 m8 x5 X, Y& B1 ]
</li>
' G- N: Q$ R! b: Y </ul>$ G; G' R5 ]% X j4 W/ e6 ]
<!-- {/foreach} -->
" u2 Y- G/ C% [& S" E" [9 S </div>
3 h' i& _4 ~/ L: s/ @ </div>
. D/ A- ~* O# q9 ~</div>
4 |& b9 G. j* Z. M1 B<div class="blank5"></div> | 0 m; r; x- P6 w, J/ {
2)、修改 /includes/lib_goods.php 文件
9 y# S# u1 a' R% [8 z在最下面增加一个函数6 l+ ?2 O/ b) k
/**
; B- V, Z& ~0 \) Z$ ?* H W: H * 调用浏览排行榜, \$ Q3 {8 `5 M/ [! G
*7 x7 a+ D4 g' \* o0 J1 t6 N8 |
* @access public8 O' U; q) v! I9 t
* @return array
; A* Y8 b x% g" O1 S */
; P* e! m+ e4 i; J" cfunction get_top10_click()# x2 `$ V8 Y$ r3 d! ]* x+ ~5 K
{
2 E8 c' `* `% P: t $sql="SELECT goods_id, goods_name, shop_price, goods_thumb " .4 A1 D6 }1 V" S$ ]. ]
'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";: D H/ m# {( A3 d
$arr = $GLOBALS['db']->getAll($sql);- X8 ~* y3 Y% g0 R2 j1 @
for ($i = 0, $count = count($arr); $i < $count; $i++)
8 @9 [6 s/ Q" g+ P W5 L4 G4 Z {: \2 J% ^& |5 D- M. E
$arr[$i]['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ?* {5 c) n7 A5 u8 E, T; [
sub_str($arr[$i]['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $arr[$i]['goods_name'];% h& h2 K( E* E! O
$arr[$i]['url'] = build_uri('goods', array('gid' => $arr[$i]['goods_id']), $arr[$i]['goods_name']);1 ^$ n; v! o3 h4 e
$arr[$i]['thumb'] = get_image_path($arr[$i]['goods_id'], $arr[$i]['goods_thumb'],true);+ e4 ~, ^; o! \- d% M. n g
$arr[$i]['price'] = price_format($arr[$i]['shop_price']);! _- z R8 l E9 [/ C0 x$ N
}( T0 U4 L7 F; c( b# c6 ?$ N
return $arr;
7 m; e, ~$ f$ t2 U# P! v6 l* s1 s8 l} | ( g0 a# V* w0 N# r* q2 t- k. s+ u V( R
3)、修改 /index.php 文件6 g+ {/ K; R% [+ R$ @# ]. Y
在$smarty->assign('top_goods', get_top10()); // 销售排行 | 9 G2 U! G- a9 V" n
下面另起一行增加$smarty->assign('top_goods_click', get_top10_click()); // 浏览排行 |
! E& L( |) u0 l* n$ g修改模板文件 /themes/default/index.dwt0 z% [: A0 j/ t2 n. y3 p1 M; P! ]
找到( c9 H3 o' ], D( T8 r/ v
<!-- #BeginLibraryItem "/library/promotion_info.lbi" --> | 在它的前面增加2 O7 |+ e% R3 y3 Q
<!-- #BeginLibraryItem "/library/top10_click.lbi" --><!-- #EndLibraryItem --> | , E/ A5 e# e2 n: R0 g. S
: A! `' C+ ?1 Y5 e6 f8 `4)、修改 /admin/includes/lib_template.php 文件
) W1 ]( G/ F1 r! Y- E1 ~2 k* p" F; [
在'/library/invoice_query.lbi' => 0, |
0 K2 F, L/ U& t! f* w6 J上边增加一行代码/ S' H( E3 b7 u* S
'/library/top10_click.lbi' => 0, | ; U1 r/ q$ L$ ]5 h5 G
5)、继续修改语言包文件 /languages/zh_cn/admin/template.php
3 N% p8 `# Q0 b在$_LANG['template_libs']['top10'] = '销售排行'; |
: Y- |; g2 V1 T* y' c下边增加一行代码# g, l& c+ a: \7 O) f1 k
$_LANG['template_libs']['top10_click'] = '浏览排行'; | ! V4 c6 w4 T" s& M
6)、修改 /themes/default/lib.xml 文件, k5 y! z: n1 F' ]& E
4 r4 A: u" ]% w a- U9 D8 D
找到. n" C5 b G+ o4 a9 O) f( F; \7 z
并且在它下面另起一行,增加
7 I4 @6 H# d1 K9 } 7)、最后进入 后台 》模板管理 》设置模板, 是不是看到了期待已久的“浏览排行”,设置一下,并清除缓存,就OK了3 A+ j3 m! B* M) p( X; y1 U. y
|