广州传奇网络

地址:广州市天河区东圃大马路富华楼C座

电话:13808825895

邮箱:gz020wbs@163.com

QQ:1564443073

网址:http://www.020wbs.com/

首页 > 二次开发Ecshop二次开发 > ecshop首页调用商品的评论

二次开发Ecshop二次开发

二次开发Ecshop二次开发

ecshop首页调用商品的评论

此函数放到首页 index.php

$this->assign('goods_comments',get_comments(5)); // 5 最新五条评论

function get_comments($n){
    $sql = 'SELECT * FROM ecs_comment '.
         ' WHERE status = 1 AND parent_id = 0 and comment_type=0 '.
         ' ORDER BY add_time DESC';
   if ($n > 0){
    $sql .= ' LIMIT ' . $n;
   } 
   $res = $GLOBALS['db']->getAll($sql);
   $comments = array();
   foreach ($res AS $idx => $row){
        $comments[$idx]['user_name']    = $row['user_name'];
        $comments[$idx]['content']    = $row['content'];
        $comments[$idx]['id_value']    = $row['id_value'];
   }
   return $comments;
}


在库目录里增加一个文件:index_goods_comments.lbi 内容如下
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<ul style="padding-left:8px">  <!--循环输出评论内容--> 
<!--{foreach from=$goods_comments item=comments}-->
   <li><a href="goods.php?id={$comments.id_value}" target="_blank">{$comments.content|truncate:10:""}</a></li>
   <!--{/foreach}-->

</ul>


首页调用 index_goods_comments.lbi文件

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