ECSHOP首页调用最新评论

第一步:将下面代码复制,并保存为一个库文件,文件名和保存路径为:

/themes/default/library/index_comments.lbi

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
if (!function_exists( "get_comments" )){
function get_comments( $num )
{
    $sql = 'SELECT * FROM ' . $GLOBALS [ 'ecs' ]->table( 'comment' ) .
             ' WHERE status = 1 AND parent_id = 0 and comment_type=0 ' .
             ' ORDER BY add_time DESC' ;
   if ( $num > 0)
   {
    $sql .= ' LIMIT ' . $num ;
   }
   //echo $sql;
          
   $res = $GLOBALS [ 'db' ]->getAll( $sql );
   $comments = array ();
   foreach ( $res AS $idx => $row )
   {
    $comments [ $idx ][ 'add_time' ]       = $comments [ $idx ][ 'add_time' ]       = local_date
( $GLOBALS [ '_CFG' ][ 'time_format' ], $row [ 'add_time' ]);
    $comments [ $idx ][ 'user_name' ]       = $row [ 'user_name' ];
    $comments [ $idx ][ 'content' ]       = $row [ 'content' ];
    $comments [ $idx ][ 'id_value' ]       = $row [ 'id_value' ];
   }
   return $comments ;
}
}
$GLOBALS [ 'smarty' ]->assign( 'my_comments' ,get_comments(10)); // 10条数据
?>
<meta http-equiv= "Content-Type" content= "text/html; charset=utf-8" >
<!-- 最新评论__Begin -->      
   <div class = "box_2" >
    <h3><span>最新评论</span></h3>
   <div class = "top10List clearfix" > ECSHOP模板http: //www.ecshop520.com
   <!--{ foreach from= $my_comments item=comments}-->
       <ul class = "clearfix" >     
       <li style= "padding:5px 10px;" >
<a href= "goods.php?id={$comments.id_value}" target= "_blank" >
{ $comments .content|truncate:21: "" }</a><br />
{ $comments .add_time}
</li>
</ul>
   <!--{/ foreach }-->
       </div>
   </div>

第二步:在ECSHOP首页模板文件中,调用这个库文件
打开 themes/default/index.dwt 文件,

1
2
</ div >
   <!--left end-->

上面增加一行调用代码

1
<!-- #BeginLibraryItem "/library/index_comments.lbi" -->  <!-- #EndLibraryItem -->

清除一下缓存

转载于:https://www.cnblogs.com/wpindesign/p/3654912.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值