在Ecshop首页上显示最新评论(评论内容&时间)-站长杂谈下载

在Ecshop首页上显示最新评论(评论内容&时间)

来自版块: 站长杂谈发表于: 2015-8-8 23:56:22
23668
0
如本资源下载地址失效,请点击此处进行反馈
开通本站Svip会员,全站资源免费下
教程以“ECSHOP2.7.2 + 官方默认模板” 为例,其他模板大同小异,
+ x7 j9 y. p* k3 i: Y% R9 `" B7 I: J- R5 X; _: _; o( F! M
效果图如下:
# w( X; Z- M" V! h 101005010245125003b77ug0.jpg
" o: P1 R$ e* W. R9 \4 ^% K% R' @8 s) i& f
第一步:
0 ?' W4 c: d  m, I将下面代码复制,并保存为一个库文件,文件名和保存路径为: /themes/default/library/index_comments.lbi 0 i3 \1 T) f& J3 Y" D  P

5 n0 |4 x, e1 `% R* N; V
<?php
) P  R9 U" b7 W6 m+ zif(!function_exists("get_comments")){9 d8 Q& {2 p/ Y9 k1 o
function get_comments($num)
1 K  |# I7 P1 |( f( T{( B* C' r' V& w; k
   $sql = 'SELECT * FROM '. $GLOBALS['ecs']->table('comment') .% O6 c6 B6 r- ?0 q+ e% J- g- s3 f/ D
            ' WHERE status = 1 AND parent_id = 0 and comment_type=0 '.( T$ ]. H$ m# p. _
            ' ORDER BY add_time DESC';3 ?# `" ]! k. j7 X& `
  if ($num > 0)
: k. s+ }" \& o7 U2 [  {4 ?' p6 m( y6 q+ x
   $sql .= ' LIMIT ' . $num;
4 v) v& F5 \" y2 o, p6 H  }
6 A9 j5 u1 ?3 D" Y  W8 W: X+ I# z: v  //echo $sql;
1 N) w, E4 \& S5 d$ o        
: B* O! R5 ~4 j3 C( v  $res = $GLOBALS['db']->getAll($sql);
4 u! G9 w( g  b  $comments = array();
9 A6 V2 R( a3 {  foreach ($res AS $idx => $row)! b8 Y9 d" M9 p) |& ?- F! t7 ?1 w
  {5 {# t; ?4 b3 ]
   $comments[$idx]['add_time']       = $comments[$idx]['add_time']       = local_date
# h. H' ^. I' W% F1 N9 ~7 J($GLOBALS['_CFG']['time_format'], $row['add_time']);  J2 ~6 q; e: O0 Q: H
   $comments[$idx]['user_name']       = $row['user_name'];& O' l+ }9 @- k" A6 M
   $comments[$idx]['content']       = $row['content'];
8 c" ?$ `* c* l3 R7 U   $comments[$idx]['id_value']       = $row['id_value'];& r9 A: ?3 f% P6 l( s
  }/ v5 p1 f! x8 i' P! z: U4 Y3 `
  return $comments;
( g; G9 N3 y' O- I% E}
$ B( ~7 r6 n8 b; w* J}* L! e" W  E( C* }0 d
$GLOBALS['smarty']->assign('my_comments',get_comments(10)); // 10条数据' n5 k1 u% R3 O
?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">6 i5 G& w; F- b
<!-- 最新评论__Begin -->      
2 D/ ~! D( F+ b; }" _+ x  <div class="box_2">
. _  ?( K) a1 Q) A  h% t   <h3><span>最新评论</span></h3>
8 E0 x- T4 {: \, [  <div class="top10List clearfix">
7 B: O9 S3 {# d! y  <!--{foreach from=$my_comments item=comments}-->
% P1 _6 A2 e( a0 p+ B      <ul class="clearfix">      
# ~  X! g, t0 w% d: c      <li style="padding:5px 10px;">0 e: W! @- M4 W) b( O
<a href="goods.php?id={$comments.id_value}" target="_blank">
, {* j- f: V1 t5 T, M+ L {$comments.content|truncate:21:""}</a><br />$ U0 W/ J7 Y# `. H9 H; h1 S7 v
{$comments.add_time}4 O3 C/ V* s. r
</li>
' q! A  v! w+ l! K1 J </ul>2 N; n3 e$ R$ n
  <!--{/foreach}-->, \+ B! V0 X. Z$ u$ W1 }
      </div>8 ]: v* I# k! g; ]
  </div>; q+ {" r% p4 N6 I
1 f( \/ x; P$ Y' i
第二步:
  [8 c! Z, J0 V+ a' ?
' T$ g% E3 B* R在ECSHOP首页模板文件中,调用这个库文件
6 T7 x: `4 ^* v2 q$ [9 r打开 themes/default/index.dwt 文件,' H: I! D1 \+ m( L& c
</div>
0 c- z) g; o& E/ z% b# E5 t  <!--left end-->
上面增加一行调用代码
$ @( Y  f. Q% Z' z
<!-- #BeginLibraryItem "/library/index_comments.lbi" -->  <!-- #EndLibraryItem -->
2 u0 w* r1 V3 Q" c' D- U
清除一下缓存
- ]& I2 u( R: f8 J

全部评论 0

您需要登录后才可以回帖 立即登录
登录
0
0
0
返回顶部