ECshop首页调用最新评论的方法,下面给你说一下步骤
1.直接建立new_comments.txt文件,打开后放置如下代码 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<div class="globalModule" id="brandList">
<h3><div id="list_t_l"><div id="list_t_r"><b>最新评论</b></div></div></h3>
<div id="global_box">
<?php if(!function_exists("get_comments")){
function get_comments($num)
{
$sql = 'SELECT a.*,b.goods_id,b.goods_thumb,b.goods_name FROM '. $GLOBALS['ecs']->table('comment') .
' AS a,'. $GLOBALS['ecs']->table('goods') .'AS b WHERE a.status = 1 AND a.parent_id = 0 and a.comment_type=0 and a.id_value=b.goods_id '.
' ORDER BY a.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'] = local_date($GLOBALS['_CFG']['time_format'], $row['add_time']);
$comments[$idx]['content'] = $row['content'];
$comments[$idx]['id_value'] = $row['id_value'];
$comments[$idx]['goods_thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true);
$comments[$idx]['goods_name'] = $row['goods_name'];
}
return $comments;
}
} ?>
<!--数据调用-最新评论开始 -->
<?php
$this->assign('my_comments',get_comments(6)); // 数据条数
?>
<!--{foreach from=$my_comments item=comments}-->
<table width="190" border="0" cellspacing="0" cellpadding="0" style="border-bottom:1px #eee dashed;">
<tr>
<td width="73" height="70" align="center"><a href="goods-{$comments.id_value}.html" target="_blank"><img src="{$comments.goods_thumb}" border="0" width="60" height="60" style="border:1px #eee solid;"/></a></td>
<td width="200" align="left" valign="top">
<div style="height:3px; overflow:hidden;"> </div>
<div><a href="goods-{$comments.id_value}.html" target="_blank"><font style="color:#bf9242;">{$comments.goods_name|truncate:10}</font></a></div>
<div>{$comments.content|truncate:100:""|truncate:18}</div>
<div style="color:#ccc;">{$comments.add_time}</div>
</td>
</tr>
</table>
<!--{/foreach}-->
<div style="clear: both;"> </div>
<p class="more">
<a href="message.php" rel="nofollow">更多评论>></a>
</p>
</div>
</div> 2.将txt文件命名为new_comments.lig放到模板下的library文件夹
3.在index.dwt要调用评论的位置加入
<!-- #BeginLibraryItem "/library/new_comments.lbi" --><!-- #EndLibraryItem -->
注意:请确保您的伪静态已成功开启 |