今天給大家介紹一篇文章,是關于ECShop首頁調用最新評論+(增加顯示評論時間),分享給大家供大家參考。具體如下:
在庫目錄里增加一個文件: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;
}
}
?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!--數據調用-最新評論開始 -->
<?php
$this->assign('my_comments',get_comments(10)); // 10條數據
?>
<div class="comments">
<!--{foreach from=$my_comments item=comments}-->
<div class="t_l f_l"><a href="goods.php?id={$comments.id_value}" target="_blank">
{$comments.content|truncate:15:""}</a></div><div class="d_r f_r">時間:
{$comments.add_time}</div>
<!--{/foreach}-->
</div>
首頁調用這個庫文件就OK了.
<!-- #BeginLibraryItem "/library/index_comments.lbi" --> <!-- #EndLibraryItem -->
以上就是本文章的內容,希望對大家有所幫助
新聞熱點
疑難解答