本教程以“ECSHOP2.7.2 + 官方默认模板” 为例,其他模板大同小异,
9 u& e) O, [6 n+ Q
$ e6 o" F! c T; x% e; e. ^- c) W- G: N效果图如下:4 Q, n, y% @; m- z
+ x( v: D _; I. ~& W9 H6 I( T
第一步:* {4 E/ }4 M8 d* P$ @! S, G/ v" j6 s
将下面代码复制,并保存为一个库文件,文件名和保存路径为: /themes/default/library/index_comments.lbi
' J% b7 v$ n* [" f" m3 `1 A; J6 W$ _9 [
<?php U& [6 n$ p+ I9 L* M3 D! K
if(!function_exists("get_comments")){ y4 p8 D' t2 b4 |) i8 Y X1 G
function get_comments($num)
1 {) v2 b8 z5 Z; r) r4 m{% Y( o% C; g6 I
$sql = 'SELECT * FROM '. $GLOBALS['ecs']->table('comment') .
( z: S& h3 h4 _. d1 M ' WHERE status = 1 AND parent_id = 0 and comment_type=0 '.
" N7 s# d2 r: j2 ~ ' ORDER BY add_time DESC';. i' F! l- t2 c( q4 w4 j
if ($num > 0)
' e7 i$ q, q7 q4 g* C/ I5 h6 W% e {; l8 @5 p" _9 v& O3 D1 P
$sql .= ' LIMIT ' . $num;
( f5 A9 p) z/ p5 \$ K1 M }( ~( V/ C# y. X5 Q1 A
//echo $sql;7 E1 F) h9 {' E# B1 @( B
5 l2 p6 ?5 x/ G# x' T $res = $GLOBALS['db']->getAll($sql);
' p5 s) ^9 f2 |& i! s $comments = array();
: J/ q2 A4 V% |# W* J+ }! z foreach ($res AS $idx => $row)* C5 r' h& Q! t3 H) ^& P
{$ _5 K% e, o4 l* ?% l5 C% N2 B2 j
$comments[$idx]['add_time'] = $comments[$idx]['add_time'] = local_date
7 q8 ~6 J1 L; g7 v($GLOBALS['_CFG']['time_format'], $row['add_time']);8 |5 Y* L6 s; i z
$comments[$idx]['user_name'] = $row['user_name'];$ y) [" |& y; B5 t- l+ y$ V
$comments[$idx]['content'] = $row['content'];
$ b6 V' o# {: Y# n $comments[$idx]['id_value'] = $row['id_value'];) A- h) V+ i1 r" C( G$ c
}
3 h% f' S, ?! {4 R1 v' S return $comments;
8 `( K, _3 H" y6 Z}1 X% m: r# g, F( Z- k- b- W
}3 ], I7 u+ Z3 W3 ~) ]( M) K
$GLOBALS['smarty']->assign('my_comments',get_comments(10)); // 10条数据
8 }( ^- p( N) q" A. @?> <meta http-equiv="Content-Type" content="text/html; charset=utf-8">/ T* e; q9 `) f
<!-- 最新评论__Begin -->
$ @3 }$ `" n- |2 c2 a2 \/ H <div class="box_2">
; I; @9 ]5 l, q. p8 ^ <h3><span>最新评论</span></h3>
9 r9 C8 e8 G, S: P <div class="top10List clearfix">
" _. g) N) B6 K" T* ]# Z( s) d <!--{foreach from=$my_comments item=comments}-->- Z% n1 ?, c t0 S2 Y
<ul class="clearfix">
+ K1 F8 X8 ?' L4 w$ o$ v5 Y! @6 N& t <li style="padding:5px 10px;">
j3 G# K2 b8 M4 K' d% [ <a href="goods.php?id={$comments.id_value}" target="_blank">! t8 z5 S3 ] L- H# v
{$comments.content|truncate:21:""}</a><br />6 G- z: N1 E2 V7 D( V+ F! }
{$comments.add_time}8 R& i8 v" N( E8 a
</li>7 b: u: F9 T2 \5 F3 P9 @- I
</ul>
" z8 g/ m' b. U# P1 N <!--{/foreach}-->
" i& ?, I7 i. @: @ S* k4 f6 y </div>- f+ D$ T6 G; m5 J: h6 g
</div>$ F+ Y3 l. a( a, v$ `% I
|
' v- E" V( v8 s, m0 w0 o第二步:: @% c, E" s9 A
. B9 e" O" [& i2 ~$ q3 c在ECSHOP首页模板文件中,调用这个库文件
. ^5 _6 a& K# u% _, @7 @ Q5 F打开 themes/default/index.dwt 文件,, c0 S% y1 P( ]/ a5 ~: G' O
在</div>& D5 g9 O9 i, d s! K
<!--left end--> | 上面增加一行调用代码; T; a% K2 l" p. r1 q: T; }
<!-- #BeginLibraryItem "/library/index_comments.lbi" --> <!-- #EndLibraryItem --> | $ J& o, B' n' }3 N! D# z
清除一下缓存, g9 M( n1 L; g
|