ECShop的評論,其實和留言板是在一起的,大家訪問自己的留言板就可以發(fā)現(xiàn)這個問題。
現(xiàn)在我們只需要把message.php的內(nèi)容調(diào)用到首頁顯示即可。在ECShop官方論壇實際上已經(jīng)提到了一些。
第1步,在index.php的最后添加一個函數(shù):
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中要調(diào)用最新評論的位置添加以下代碼:
<!-- {foreach from=$pvnewcomments item=idxcomment} -->
<div style="margin: 8px 0 0 0;"><!-- {if $idxcomment.user_name eq ''} –->匿名用戶<!-- {else} -->{$idxcomment.user_name}<!-- {/if} --><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>
<!-- {/foreach} -->
具體調(diào)用條數(shù)、條件等可相應(yīng)修改SQL語句。
好了,趕快把自己的商城也修改一下吧,讓評論也在首頁調(diào)用出來。
注:comment_rank = 5 (評論等級)