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

ECshop首页调用最新评论的办法

2019-10-16 21:44:21
字体:
来源:转载
供稿:网友
<?php
if(!function_exists("get_comments")){
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;
}
}
?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
       <!--数据调用-最新评论开始 -->      
    <?php
        $this->assign('my_comments',get_comments(6)); // 6代表会条数据
    ?>        
<div id="promotion">
  <div class="sortbg">
    <div id="comments_left"></div>
    <div id="comments_right"></div>
  </div>
  <div class="sort">
    <ul   style="padding-left:8px">
      <!--{foreach from=$my_comments item=comments}-->
      <li><a href="goods.php?id={$comments.id_value}" target="_blank">{$comments.content|truncate:10:""}</a></li>
      <!--{/foreach}-->
    </ul>
  </div>
</div>

首页调用这个库文件就OK了.
<!-- #BeginLibraryItem "/library/index_comments.lbi" --><!-- #EndLibraryItem -->
样式大家自己根据网店的风格调整下!
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表