官方微博: 腾讯  
首页 > ECSHOP教程 > ECSHOP模板教程 > ECSHOP商城首页修改 > ECSHOP首页调用显示最新商品评论

ECSHOP首页调用显示最新商品评论

ECSHOP教程 / ecshop 教程网(www.ecshop119.com) 2013-07-12

ECSHOP首页显示最新评论,首页调用商品评论新建立一个 index_comments.lbi 库文件

然后在index.dwt 要显示的位置调用:

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

 

 

index_comments.lbi 内容为:

<?php

if(!function_exists("get_comments")){
function get_comments($num)
{
   $sql = 'SELECT a.*,b.goods_id,b.goods_thumb,b.goods_name FROM '. $GLOBALS['ecs']->table('comment') .
            ' AS a,'. $GLOBALS['ecs']->table('goods') .'AS b WHERE a.status = 1 AND a.parent_id = 0 and LENGTH(a.content)>0  and a.comment_type=0 and a.id_value=b.goods_id  '.
            ' ORDER BY a.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']      = local_date($GLOBALS['_CFG']['date_format'], $row['add_time']);
   $comments[$idx]['content']       = $row['content'];
   $comments[$idx]['id_value']      = $row['id_value'];
   $comments[$idx]['goods_thumb']   = get_image_path($row['goods_id'], $row['goods_thumb'], true);
   $comments[$idx]['goods_name']    = $row['goods_name'];
  }
  return $comments;
}
}

?>
<script type="text/javascript">
function player(id){
var id=document.getElementById(id)
id.style.display="block";
}
function clocer(id){
var id=document.getElementById(id)
id.style.display="none";
}
</script>
<!--数据调用-最新评论开始 -->      
<?php
   $this->assign('my_comments',get_comments(10)); // 数据条数
?>



    <ul>
    <!--{foreach from=$my_comments item=comments name=id}-->
      <li OnMouseOver="player('any{$smarty.foreach.id.iteration}');" onMouseOut="clocer('any{$smarty.foreach.id.iteration}');" style="cursor:hand;"><span>{$comments.add_time}</span>
      <a href="goods-{$comments.id_value}.html" title="{$comments.content|escape:html}" target="_blank">{$comments.content|truncate:10:""}</a>
      <div class="divbox">
       <div id="any{$smarty.foreach.id.iteration}" class="more" OnMouseOver="player('any{$smarty.foreach.id.iteration}');" onMouseOut="clocer('any{$smarty.foreach.id.iteration}');">
       <a href="goods-{$comments.id_value}.html" title="{$comments.content|escape:html}" target="_blank"><img src="{$comments.goods_thumb}" alt="{$comments.goods_name|escape:html}" width="120px" height="120px"/></a>
       </div>
      </div>
      </li>
    <!--{/foreach}-->
    </ul>

转载请注明:ECshop119模板屋-ECshop教程网(全国最专业的ECSHOP插件制作商-专业ECSHOP二次开发)

帮助目录

在线反馈

可以将问题或建议反馈给我们。

提交在线反馈

与网友交流ECSHOP开发修改。

加入QQ群交流