首页 > 运营 > 帮助中心 > 正文

ECSHOP二次开发之首页调用商品评论

2019-10-16 21:42:49
字体:
来源:转载
供稿:网友
1.首先在library创建index_comments.lib文件,
2.然后index.php写一个方法:
function get_comments($num)
{
   $sql = 'SELECT * FROM ecs_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]['user_name']       = $row['user_name'];
   $comments[$idx]['content']       = $row['content'];
            $comments[$idx]['id_value']       = $row['id_value'];

  }
  return $comments;
}

3.在index.php大概128行处添加$smarty->assign('my_comments',get_comments(10));              // 用户评论

4.index_comments添加,    <!--{foreach from=$my_comments item=comments}-->
    <a href="goods.php?id={$comments.id_value}" target="_blank" style="float:left;">{$comments.content|truncate:30:""}</a>
    <font style="margin-left:20px; color:#CCC; float:right;">{$comments.add_time}</font><br>

    <!--{/foreach}-->

5.在首页index.dwt调用商品用户评论
<!-- #BeginLibraryItem "/library/index_comments.lbi" --><!-- #EndLibraryItem -->
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表