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

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

开通本站Svip会员,全站资源免费下
教程以“ECSHOP2.7.2 + 官方默认模板” 为例,其他模板大同小异,+ c3 i6 h- ?; t

6 P9 e* |  m. m7 c; o0 L效果图如下:
8 R( i! c6 n2 a" w; ~ 101005010245125003b77ug0.jpg . W+ Y2 m/ _" O3 b7 D" h: r  s  T; f# ?

" `0 F5 K1 i) Y! V: l第一步:/ b, Y- N, e% F" q% y
将下面代码复制,并保存为一个库文件,文件名和保存路径为: /themes/default/library/index_comments.lbi
+ I9 w0 m" \1 Y8 S% H1 G- T4 ^/ i$ z
<?php
$ _0 v0 T: c3 z! ]2 vif(!function_exists("get_comments")){
5 `+ g7 C1 {/ i- j' [function get_comments($num)2 g9 P* f# z6 \0 v
{
) U: u# }  s1 N9 {   $sql = 'SELECT * FROM '. $GLOBALS['ecs']->table('comment') .
% R8 d6 n5 K) @9 U            ' WHERE status = 1 AND parent_id = 0 and comment_type=0 '.- Y, |" u$ F6 {% P) F
            ' ORDER BY add_time DESC';
+ i" s0 j. J/ D& V0 }  if ($num > 0)2 e1 N5 b$ R; @7 Y5 ]) B/ k
  {/ X# k8 b* b# j0 X
   $sql .= ' LIMIT ' . $num;1 o* P- n" g; c
  }# z6 l* D2 J, l  {: q3 ?
  //echo $sql;) y2 e3 f: m0 s* ?7 g) b% D7 X
        
2 _" Z- \! l/ e8 G! T8 f: p" ~  $res = $GLOBALS['db']->getAll($sql);
% s3 U: @7 H2 H+ i" `  $comments = array();
% Q" S# L/ Q! D' j  foreach ($res AS $idx => $row)* Y+ X1 _, ~' t2 U1 d2 W: A
  {( e. u, F/ [& r  r' n1 N+ f
   $comments[$idx]['add_time']       = $comments[$idx]['add_time']       = local_date8 Z" [  x% I4 S1 J% D$ G% \. C
($GLOBALS['_CFG']['time_format'], $row['add_time']);
! {7 Y" T1 v4 h   $comments[$idx]['user_name']       = $row['user_name'];. L6 l( `0 c9 K7 S* T& Z2 \
   $comments[$idx]['content']       = $row['content'];
- q, C, q8 {; w6 n   $comments[$idx]['id_value']       = $row['id_value'];  H8 [! H; \: B! R/ k: x
  }
! j% u  v7 }9 {  return $comments;. M8 p& B7 x) ?& h1 b  a  p
}( J* F: z! E( p: A" [
}
- P2 k) }% Y; [9 ]& t$GLOBALS['smarty']->assign('my_comments',get_comments(10)); // 10条数据0 S: e; [8 Y) c- h$ r3 g0 X
?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
8 s3 n  C' h) b/ \9 ?( _. l<!-- 最新评论__Begin -->      
- t) M' T+ _$ N5 `  <div class="box_2">
' O% \$ R1 _5 q2 _' \3 D   <h3><span>最新评论</span></h3>
" z, P: {; ~; Y9 e6 X5 L# J  G  <div class="top10List clearfix">. j/ h4 ^( X! @* ]3 Q( V1 K3 H
  <!--{foreach from=$my_comments item=comments}-->0 Y6 L7 e) ~+ R! h: D  V: m
      <ul class="clearfix">      
+ K5 w- {0 K, O6 a& h. D      <li style="padding:5px 10px;">8 }  B3 x4 J5 S7 l
<a href="goods.php?id={$comments.id_value}" target="_blank">
3 v% H8 w+ q0 J {$comments.content|truncate:21:""}</a><br />4 J- c7 Q! G) G# j2 D5 R
{$comments.add_time}
1 f: C  d2 T0 \3 j$ F# Z- R </li>
1 D  e5 w3 q% M5 P# p </ul>
) I5 ]% K. ~5 ~5 j; q  <!--{/foreach}-->
# W" q: Y, L, c0 W! {      </div>; V3 d- x' E' e+ {: x9 y" S  d. \
  </div>' J2 I) o0 B% m/ Z3 Q8 r
0 E* }& c  }/ q6 i0 S1 H2 e; H
第二步:
2 n( G" s9 s$ l2 `
$ S, b# M8 s" q* i: k& v  |在ECSHOP首页模板文件中,调用这个库文件# H( |" Y) O  ~' Z1 a
打开 themes/default/index.dwt 文件,- e. O' f! A- q- i
</div>8 V* B8 J8 |0 i* K9 [$ A7 [
  <!--left end-->
上面增加一行调用代码( A- f# o' I& ~. k
<!-- #BeginLibraryItem "/library/index_comments.lbi" -->  <!-- #EndLibraryItem -->
  t" }4 R4 [5 q( }7 V3 l& O% i
清除一下缓存; p4 Y( y4 E! ]' f2 a; Y. O1 }3 F8 Z

全部评论 0

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