ecshop模板首頁(yè)上如何讓顯示最新評(píng)論呢?
此方法是針對(duì)默認(rèn)模板的修改方法,如果是其他模板,修改方法相同,可自己修改樣式:
第一步:
將下面代碼復(fù)制,并保存為一個(gè)庫(kù)文件,文件名和保存路徑為:/themes/default/library/index_comments.lbi
<?php
if(!function_exists("get_comments")){
functionget_comments($num)
{
$sql='SELECT*FROM'.$GLOBALS['ecs']->table('comment').
'WHEREstatus=1ANDparent_id=0andcomment_type=0'.
'ORDERBYadd_timeDESC';
if($num>0)
{
$sql.='LIMIT'.$num;
}
//echo$sql;
$res=$GLOBALS['db']->getAll($sql);
$comments=array();
foreach($resAS$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;
}
}
$GLOBALS['smarty']->assign('my_comments',get_comments(10));//10條數(shù)據(jù)
?>
<metahttp-equiv="Content-Type"content="text/html;charset=utf-8">
<!--最新評(píng)論__Begin-->
<divclass="box_2">
<h3><span>最新評(píng)論</span></h3>
<divclass="top10Listclearfix">
<!--{foreachfrom=$my_commentsitem=comments}-->
<ulclass="clearfix">
<listyle="padding:5px10px;">
<ahref="goods.php?id={$comments.id_value}"target="_blank">
{$comments.content|truncate:21:""}</a><br/>
{$comments.add_time}
</li>
</ul>
<!--{/foreach}-->
</div>
</div>
第二步:
在ecshop首頁(yè)模板文件中,調(diào)用這個(gè)庫(kù)文件
打開themes/default/index.dwt文件,
在
</div>
<!--leftend-->
上面增加一行調(diào)用代碼
<!--#BeginLibraryItem"/library/index_comments.lbi"--><!--#EndLibraryItem-->
新聞熱點(diǎn)
疑難解答
圖片精選