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
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 -->
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 -->
转载请说明出处
知优网 » ECSHOP二次开发之首页调用商品评论(ecshop二次开发笔记)
知优网 » ECSHOP二次开发之首页调用商品评论(ecshop二次开发笔记)