<div class="content_topp"> 添加独立商品评论页面可分页显示
通过以下方法可以实现使用一个单独立的页面来显示所有的评论,并在评论中显示会员 评论的商品 评论内容等。
教程开始:
首先建立三个文件,testp.php test.dwt test.lbi,test.php 就是最终的评论页面。
在test.php中加入以下内容
$page = isset($_REQUEST['page']) && intval($_REQUEST['page']) > 0 ? intval($_REQUEST['page']) : 1;
$size = 15;
$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');
$smarty->display('test.dwt');
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;
}
function get_comments_count()
{
return $GLOBALS['db']->getOne('SELECT COUNT(*) FROM ' . $GLOBALS['ecs']->table('comment'));
}
?>
test.dwt中写入以下内容
test.lbi 中写入以下内容
"游客""{$comments.user_name}"在{$comments.add_time} 评论 <a style=/codecode class="php string" style="font-family: Monaco, Menlo, Consolas, 'Courier New', monospace; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; background-image: none !important; border: 0px !important; bottom: auto !important; float: none !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: blue !important;""width:107;"/code code class="php plain" style="font-family: Monaco, Menlo, Consolas, 'Courier New', monospace; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; background-image: none !important; border: 0px !important; bottom: auto !important; float: none !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;"href=/codecode class="php string" style="font-family: Monaco, Menlo, Consolas, 'Courier New', monospace; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; background-image: none !important; border: 0px !important; bottom: auto !important; float: none !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: blue !important;""goods-{$comments.id_value}.html"/code code class="php plain" style="font-family: Monaco, Menlo, Consolas, 'Courier New', monospace; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; background-image: none !important; border: 0px !important; bottom: auto !important; float: none !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;">"{$comments.goods_name}":
"{$comments.content}"
然后修改 includes\lib_main.php 大约509 后面加入以下代码然后修改 includes\lib_main.php 大约509 后面加入以下代码
case 'test':
$uri_args = array('page'=>$page, 'order' => $order);
break;
最后把 test.php放入站点根目录,test.dwt放入模板目录,test.lbi放入对应模板的
库项目目录。
访问test.php就可以看到评论已经显示
并可以分页了,这里只是介绍了程序的实现方法,模板中并未引入头部和底部的模板也没有为评论显示设计样式。在实际使用时可根据具体的网站来来设计评论显示的样式。
|
|