如下是修改方法。
首先創建三個文件,testp.php test.dwt test.lbi,test.php 就是最終的評論頁面。
在test.php中加入如下內容
<?PHP
$page = isset($_REQUEST['page']) && intval($_REQUEST['page']) > 0 ? intval($_REQUEST['page']) : 1;
$size = 15; php
$count = get_comments_count();
$max_page = ($count> 0) ? ceil($count / $size) : 1;
if ($page > $max_page)
{
$page = $max_page;
}
$goodslist = get_comments($size, $page);
$smarty->assign('my_comments', $goodslist);
assign_pager( 'test', '', $count, $size, '', $order, $page,'', '', '', '', '','', '', '');
assign_dynamic('test'); html
$smarty->display('test.dwt'); sql
function get_comments($size, $page)
{
$display = $GLOBALS['display'];
/* 得到評論列表 */
$sql = 'SELECT a.*,b.goods_id,b.goods_name,user_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';
$res = $GLOBALS['db']->selectLimit($sql, $size, ($page - 1) * $size);
$arr = array();
while ($row = $GLOBALS['db']->fetchRow($res))
{
$arr[$row['comment_id']]['type'] = $row['goods_type'];
$arr[$row['comment_id']]['add_time'] = local_date($GLOBALS['_CFG']['time_format'], $row['add_time']);
$arr[$row['comment_id']]['content'] = $row['content'];
$arr[$row['comment_id']]['id_value'] = $row['id_value'];
$arr[$row['comment_id']]['goods_name'] = $row['goods_name'];
$arr[$row['comment_id']]['user_name'] = $row['user_name'];
}
return $arr; fetch
} 網站
function get_comments_count()
{
return $GLOBALS['db']->getOne('SELECT COUNT(*) FROM ' . $GLOBALS['ecs']->table('comment'));
}
?>
test.dwt中寫入如下內容
<!-- #BeginLibraryItem "/library/test.lbi" --><!-- #EndLibraryItem -->
<!-- #BeginLibraryItem "/library/pages.lbi" --><!-- #EndLibraryItem -->
test.lbi 中寫入如下內容
<!--{foreach from=$my_comments item=comments}-->
<!-- {if $comments.user_name eq ''} -->" 遊客"<!-- {else} -->"{$comments.user_name}"<!-- {/if} -->在 {$comments.add_time} 評 論 <a style="width:107;" href="goods-{$comments.id_value}.html" >"{$comments.goods_name}"</a>:<br />
<div style="color:#f92ab4;">"{$comments.content}"</div><br />
<!-- {/foreach} -->
而後修改 includes\lib_main.php 大約509 後面加入如下代碼
case 'test':
$uri_args = array('page'=>$page, 'order' => $order);
break;
最後把 test.php放入站點根目錄,test.dwt放入模板目錄,test.lbi放入對應模板的 庫項目目錄。
訪問test.php就能夠看到評論已經顯示 並能夠分頁了,這裏只是介紹了程序的實現方法,模板中並未引入頭部和底部的模板也沒有爲評論顯示設計樣式。在實際使用時可根據具體的網站來來設計評論顯示的樣式。 設計
若是翻頁失效,就到pages.lbi中找到 <a href="{$item}">[{$key}]</a>改成 <a href="{$item}?page={$key}">[{$key}]</a> orm