zblogphp评论显示用户别名的方法
147
4
我们知道,wordpress里面有设置,可以选择在前台显示用户自己设置的别名,这样可以避免让他人看到登录名,从而去破解登录密码。
而zblogPHP则不行,虽然在后台能设置用户别名,但评论部分只能显示用户用户登录名,因此,需要修改。
方法如下:
找到模板目录下comment.php文件:
把
<span style="line-height: 1.5;"><span </span><span class="keyword" style="line-height: 1.5;">class</span><span style="line-height: 1.5;">=</span><span class="string" style="line-height: 1.5;">"dot"</span><span style="line-height: 1.5;">>{</span><span class="vars" style="line-height: 1.5;">$key</span><span style="line-height: 1.5;">+1}#</span><a href=</span><span class="string" style="line-height: 1.5;">"{$comment.Author.HomePage}"</span><span style="line-height: 1.5;"> rel=</span><span class="string" style="line-height: 1.5;">"nofollow"</span><span style="line-height: 1.5;"> target=</span><span class="string" style="line-height: 1.5;">"_blank"</span><span style="line-height: 1.5;">>{</span><span class="vars" style="line-height: 1.5;">$comment</span><span style="line-height: 1.5;">.Author.Name}</a>&nbsp;&nbsp;<span>{</span><span class="vars" style="line-height: 1.5;">$comment</span><span style="line-height: 1.5;">.Time()}&nbsp;<a href=</span><span class="string" style="line-height: 1.5;">"#comment"</span><span style="line-height: 1.5;"> onclick=</span><span class="string" style="line-height: 1.5;">"RevertComment('{$comment.ID}')"</span><span style="line-height: 1.5;">>回复</a></span></span>
修改为:
<div class="dp-highlighter">
<div class="bar"></div>
{<span class="keyword">if</span> <span class="vars">$comment</span>.Author.Email==<span class="vars">$article</span>.Author.Email}
<span <span class="keyword">class</span>=<span class="string">"dot"</span>>{<span class="vars">$key</span>+1}#</span>{<span class="vars">$comment</span>.Author.Alias}&nbsp;&nbsp;<span>{<span class="vars">$comment</span>.Time()}&nbsp;<a href=<span class="string">"#comment"</span> onclick=<span class="string">"RevertComment('{$comment.ID}')"</span>>回复</a></span>
</div>
{<span class="keyword">else</span>}
<span <span class="keyword">class</span>=<span class="string">"dot"</span>>{<span class="vars">$key</span>+1}#</span><a href=<span class="string">"{$comment.Author.HomePage}"</span> rel=<span class="string">"nofollow"</span> target=<span class="string">"_blank"</span>>{<span class="vars">$comment</span>.Author.Name}</a>&nbsp;&nbsp;<span>{<span class="vars">$comment</span>.Time()}&nbsp;<a href=<span class="string">"#comment"</span> onclick=<span class="string">"RevertComment('{$comment.ID}')"</span>>回复</a></span>
</div>
<div <span class="keyword">class</span>=<span class="string">"msgarticle"</span>>{<span class="vars">$comment</span>.Content}
{<span class="keyword">foreach</span> <span class="vars">$comment</span>.Comments <span class="keyword">as</span> <span class="vars">$comment</span>}
{template:comment}
{/<span class="keyword">foreach</span>}
</div>
{/<span class="keyword">if</span>}
</div>
增加一个判断,{if $comment.Author.Email==$article.Author.Email}
,意思为如果评论者的邮箱与文章作者的邮箱相同,,那么则显示别名,如不是则显示用户名称。