如何在ECShop首页调用评论
ECShop的评论,其实和留言板是在一起的,大家访问自己的留言板就可以发现这个问题,现在我们只需要把message.php的内容调用到首页显示即可,在ECShop官方论坛实际上已经提到了一些.
第1步,在index.php的最后添加一个函数:
- function index_get_comments()
- {
- $sql = ‘SELECT id_value, user_name, content, add_time FROM ‘ . $GLOBALS['ecs']->table(‘comment’) . ‘ WHERE comment_rank = 5 AND status = 1 ORDER BY comment_id DESC LIMIT 5′;
- $res = $GLOBALS['db']->getAll($sql);
- $pvnewcomments = array();
- foreach ($res AS $row)
- {
- $pvnewcomments[] = array(‘id_value’ => $row['id_value'],
- ‘user_name’ => $row['user_name'],
- ‘content’ => $row['content'],
- ‘add_time’ => date(“Y-m-d H:i:s”, $row['add_time']));
- }
- return $pvnewcomments;
- }
第2步,在index.php中很多$smarty->assign那段添加一行:
$smarty->assign('pvnewcomments', index_get_comments());
第3步,在模板index.dwt中要调用最新评论的位置添加以下代码:
- from=$pvnewcomments item=idxcomment} –>
- <div style=”margin: 8px 0 0 0;”>>匿名用户>{$idxcomment.user_name}><span style=”color: #999; font-size: 10px;”>({$idxcomment.add_time})span>div>
- <div style=”padding: 0 0 8px 0; border-bottom: 1px dotted #ccc;”><a href=”goods.php?id={$idxcomment.id_value}”>{$idxcomment.content}a>div>
- >
具体调用条数、条件等可相应修改SQL语句,好了,赶快把自己的商城也修改一下吧,让评论也在首页调用出来.

