A-A+
ecshop显示最新评论和评论时间的方法
在购物站点中,有时候需要将站点的最新评论发布到首页面去显示,评论是现在网民比较乐于查看的兴趣,夏日博客通常上购物站点,基本上都会看看好评差评,虽然这些评论都是刷出来的,但还是有一定的参考价值的,除了普通的文字评论标题外,现在京东和天猫上都配有了图文的评论,给人的感觉很好,让网购的消费人群可以更直观的看到拿到产品时产品的样子,下面夏日就来介绍一下如何在ECSHOP系统的首页显示最新的评论内容和评论时间的方法。
第一步:将下面代码复制,并保存为一个库文件,文件名和保存路径为: /themes/default/library/index_comments.lbi
<?php if(!function_exists("get_comments")){ function get_comments($num) { $sql = 'SELECT * FROM '. $GLOBALS['ecs']->table('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]['add_time'] = $comments[$idx]['add_time'] = local_date ($GLOBALS['_CFG']['time_format'], $row['add_time']); $comments[$idx]['user_name'] = $row['user_name']; $comments[$idx]['content'] = $row['content']; $comments[$idx]['id_value'] = $row['id_value']; } return $comments; } } $GLOBALS['smarty']->assign('my_comments',get_comments(10)); // 10条数据 ?> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <!-- 最新评论__Begin --> <div class="box_2"> <h3><span>最新评论</span></h3> <div class="top10List clearfix"> <!--{foreach from=$my_comments item=comments}--> <ul class="clearfix"> <li style="padding:5px 10px;"> <a href="goods.php?id={$comments.id_value}" target="_blank"> {$comments.content|truncate:21:""}</a><br /> {$comments.add_time} </li> </ul> <!--{/foreach}--> </div> </div>
第二步:在ECSHOP首页模板文件中,调用这个库文件,打开 themes/default/index.dwt 文件,在:
</div> <!--left end-->
上面增加一行调用代码:
<!-- #BeginLibraryItem "/library/index_comments.lbi" --> <!-- #EndLibraryItem -->
清除一下缓存