关于ecshop商品的用户评论栏内添加用户等级、注册时间
2016-09-11 20:39 来源:www.chinab4c.com 作者:ecshop专家
一、实现步骤
涉及到三个文件的代码编辑与设计,这三个文件分别
是:/commen.php;/themes/default/library/comments_list.lbi;/include/lib_main.php.
第一步:打开/include/lib_main.php,找到函数
function assign_comment($id, $type, $page = 1)往下看找到里面的一个sql调用语
句:
1
2
3
4
|
$sql = 'SELECT * FROM ' . $GLOBALS['ecs']->table('comment') .
" WHERE id_value = '$id' AND comment_type = '$type' AND status = 1
AND parent_id = 0".
' ORDER BY comment_id DESC'
|
我们需要用户的更详细信息,所以需要将表comment和users、user_rank左连接后查询获取更多的信息,
上面整体修改为:
1
2
3
4
5
6
|
$sql = "SELECT c.*, u.reg_time,u.user_rank,u.last_login,r.rank_name FROM "
.$GLOBALS['ecs']->table('comment') . " c".
" LEFT JOIN".$GLOBALS['ecs']->table('users')." u ON c.user_name = u.user_name".
" LEFT JOIN".$GLOBALS['ecs']->table('user_rank') . " AS r ON r.rank_id = u.user_rank " .
" WHERE id_value = '$id' AND comment_type = '$type' AND status = 1 AND c.parent_id = 0".
" ORDER BY comment_id DESC" ;
|
再往下看,找到:
1
2
3
4
5
6
7
8
9
|
$arr[$row['comment_id']]['email'] = $row['email'];
$arr[$row['comment_id']]['username'] = $row['user_name'];
$arr[$row['comment_id']]['content'] = str_replace('\\r\\n', '<br />',
htmlspecialchars($row['content']));
$arr[$row['comment_id']]['content'] = str_replace('\\n', '<br />', $arr
[$row['comment_id']]['content']);
$arr[$row['comment_id']]['rank'] = $row['comment_rank'];
$arr[$row['comment_id']]['add_time'] = local_date($GLOBALS['_CFG']['time_format'],
$row['add_time']);
|
在下面插入你所需要的显示的用户信息,比如我的就是要显示用户的等级信息、等级名称、
注册时间:
1
2
3
|
$arr[$row['comment_id']]['userrank'] = $row['user_rank'];
$arr[$row['comment_id']]['rankname'] = $row['rank_name'];
$arr[$row['comment_id']]['regtime'] = local_date('Y-m-d H:i ',$row['reg_time']);
|
第二部:打开comment.php,找到:
1
2
3
4
5
6
7
8
9
10
|
if ($result['error'] == 0)
{
$comments = assign_comment($cmt->id, $cmt->type, $cmt->page);
$smarty->assign('comment_type', $cmt->type);
$smarty->assign('id', $cmt->id);
$smarty->assign('username', $_SESSION['user_name']);
$smarty->assign('email', $_SESSION['email']);
$smarty->assign('comments', $comments['comments']);
$smarty->assign('pager', $comments['pager']);
|
后面插入:
1
2
3
|
$smarty->assign('userrank', $_SESSION['user_rank']);
$smarty->assign('rankname', $_SESSION['rank_name']);
$smarty->assign('regtime', $_SESSION['reg_time']);
|
第三步:打开comments_list.lbi,找到用户评论的区域代码:
1
2
3
4
5
6
7
8
9
10
|
<div class="commentsTit">
<!-- {if $comment.username} -->
<b class="username">{$comment.username|escape:html}:</b>
<!-- {else} -->
<b class="username">{$lang.anonymous}:</b>
<!-- {/if} -->
给出 <img src="../images/stars{$comment.rank}.gif"
alt="{$comment.comment_rank}" /> 评分<span>
( {$comment.add_time} )</span>
</div>
|
整体修改为:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
<div class="commentsTit">
<!-- {if $comment.username} -->
<b class="username"> <img src="../images/memtit.gif" />
{$comment.username|escape:html}:</b>
给出 <img src="../images/stars{$comment.rank}.gif"
alt="{$comment.comment_rank}" /> 评分
<span>(注册时间:{$comment.regtime}) </span>
<!---此处想出现什么 你就用用什么 值分别为 {$comment.userrank}{$comment.rankname}{$comment.regtime}--->
<!-- {else} -->
<b class="username"><img src="../images/Anonytit.gif" />
{$lang.anonymous}:</b>给出 <img src="../images/stars{$comment.rank}.gif"
alt="{$comment.comment_rank}" /> 评分
<!-- {/if} -->
</div>
|
最近更新
常用插件
- ecshop2.7.1邮件发送插件
ecshop2.7.1邮件发送插件:该插件主要的开发思想是源于ecshop短信发送系统...
- ecshop没登陆情况下订单查
ecshop没登陆情况下订单查询插件,主要是针对ecshop在没有登陆的情况下...
- ecshop2.7.2生成虚拟订单2.
以前我们开发过ecshop下的虚拟订单,就是客户在访问的时候,会自动生...
- ecshop二次开发商品购买增
图片1香...
- ecshop最小购买数量控制插
ecshop最小购买数量控制插件,这个插件主要是为我们提供一个十分方便...