ecshop首页调用评论及图片

1、在library文件夹中建立一个名为index_comment.lbi文件

2、输入以下代码

 1 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
 2 <?php
 3 if(!function_exists("get_comments")){
 4 function get_comments($num)
 5 {
 6    $sql = 'SELECT a.*,b.goods_id,b.goods_thumb,b.goods_name FROM '. $GLOBALS['ecs']->table('comment') .
 7             ' AS a,'. $GLOBALS['ecs']->table('goods') .'AS b WHERE a.status = 1 AND a.parent_id = 0 and a.comment_type=0 and a.id_value=b.goods_id '.
 8             ' ORDER BY a.add_time DESC';
 9 if ($num > 0)
10 {
11    $sql .= ' LIMIT ' . $num;
12 }
13 //echo $sql;
14         
15 $res = $GLOBALS['db']->getAll($sql);
16 $comments = array();
17 foreach ($res AS $idx => $row)
18 {
19    $comments[$idx]['add_time']       = local_date($GLOBALS['_CFG']['time_format'], $row['add_time']);
20    $comments[$idx]['content']       = $row['content'];
21    $comments[$idx]['id_value']       = $row['id_value'];
22    $comments[$idx]['goods_thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true);
23    $comments[$idx]['goods_name']       = $row['goods_name'];
24 }
25 return $comments;
26 }
27 }
28 ?>
29 <?php
30    $this->assign('my_comments',get_comments(8)); // 数据条数
31 ?>
32 <div>
33   <h1> 顾客评论 </h1>
34   <div>
35     <!-- {foreach from=$my_comments item=comments} -->
36     <dl>
37       <dt><a href="goods.php?id={$comments.id_value}" target="_blank"><img src="{$comments.goods_thumb}" alt="" /></a></dt>
38       <dd><a href="goods.php?id={$comments.id_value}" style="color:#FF6400; font-weight:bold">名称:{$comments.goods_name}</a></dd>
39       <dd>{$comments.content|truncate:100:""}</dd>
40       <dd>时间:{$comments.add_time}</dd>
41     </dl>
42     <!-- {/foreach} -->
43   </div>
44 </div>
View Code

3、在index.dwt文件的评论的地方加入<!-- #BeginLibraryItem "/library/pl_y.lbi" -->  <!-- #EndLibraryItem -->

完成

转载于:https://www.cnblogs.com/iz100/p/3182380.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值