ECSHOP首页调用最新评论插件

2016-09-07 22:03 来源:www.chinab4c.com 作者:ecshop专家


ECSHOP首页调用最新评论插件,chinab4c提供如下修改代码:

  1. <?php
  2. if(!function_exists("get_comments")){
  3. function get_comments($num)
  4. {
  5. $sql = 'SELECT a.*,b.goods_id,b.goods_thumb,b.goods_name FROM '. $GLOBALS['ecs']->table('comment') .
  6. ' AS a,'. $GLOBALS['ecs']->table('goods') .'AS b WHERE a.status = 1 AND a.parent_id = 0 and a.comment_type=0 and 
  7.  
  8. a.id_value=b.goods_id '.
  9. ' ORDER BY a.add_time DESC';
  10. if ($num > 0)
  11. {
  12. $sql .= ' LIMIT ' . $num;
  13. }
  14. //echo $sql;
  15.  
  16. $res = $GLOBALS['db']->getAll($sql);
  17. $comments = array();
  18. foreach ($res AS $idx => $row)
  19. {
  20. $comments[$idx]['add_time'] = local_date($GLOBALS['_CFG']['time_format'], $row['add_time']);
  21. $comments[$idx]['content'] = $row['content'];
  22. $comments[$idx]['id_value'] = $row['id_value'];
  23. $comments[$idx]['goods_thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true);
  24. $comments[$idx]['goods_name'] = $row['goods_name'];
  25. }
  26. return $comments;
  27. }
  28. }
  29. ?>
  30. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  31. <!--数据调用-最新评论开始 --> 
  32. <?php
  33. $this->assign('my_comments',get_comments(5)); // 数据条数
  34. ?>
  35. <!--{foreach from=$my_comments item=comments}-->
  36. <table width="290" border="0" cellspacing="0" cellpadding="0" style=" border-bottom:1px #ccc dashed;">
  37. <tr>
  38. <td width="73" height="70" align="center"><a href="goods.php?id={$comments.id_value}" target="_blank"><img 
  39.  
  40. src="{$comments.goods_thumb}" border="0" width="60" height="60" style=" border:1px #CCCCCC solid;"/></a></td>
  41. <td width="473" align="left" valign="top">
  42. <div style="height:3px; overflow:hidden;"> </div>
  43. <div><a href="goods.php?id={$comments.id_value}" target="_blank"><font style=" color:#FF0000; font-size:14px;">
  44.  
  45. {$comments.goods_name}</font></a></div>
  46. <div><img src="../images/pl.gif" width="38" height="19" align="absmiddle">{$comments.content|truncate:100:""}</div>
  47. <div style="color:#999999;">时间:{$comments.add_time}</div>
  48. </td>
  49. </tr>
  50. </table>
  51. <!--{/foreach}-->

此处:

  1. <?php
  2.  
  3. $this->assign('my_comments',get_comments(5)); // 数据条数   这里的5 是你要调用的数量。。。
  4.  
  5. ?>

(责任编辑:chinab4c)