ECSHOP首页如何调用产品最新评论
首先,在库目录里增加一个文件:Newcomments.lbi 将以下内容加入此文件:
<?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(5)); // 5代表会条数据
?>
此处是循环输出评论内容:
<!–{foreach from=$my_comments item=comments}–>
<li><a href=”goods.php?id={$comments.id_value}” target=”_blank”>{$comments.content|truncate:10:”"}</a></li>
<!–{/foreach}–>
然后以上内容只是功能显示,在相应处加入你需要的样式即可。
最后,首页调用此库文件就可以了.
<!– #BeginLibraryItem “/library/Newcomments.lbi” –> <!– #EndLibraryItem –>