想不想让他人再次评论你的WordPress日志时,发现多余的资料输入框(一般是三行)已经不见了,今天Blinux转载MG12的改善WordPress 访客评论时的用户体验一文.

如果我的教程看不懂,可以直接上mg12的blog上去瞧瞧.

  • 1.在当前主题的comments.php文件中查找评论资料输入框相关代码.

以下是本主题的相关代码,具体因情况而异.

<p><input type="text" name="author" id="author" value="<?php echo $comment_author; ?/>" size="22" tabindex="1" < ?php if ($req) echo "aria-required='true'"; ?> /> 
<label for="author"><small>Name < ?php if ($req) echo "(required)"; ?></small></label></p> 
 
<p><input type="text" name="email" id="email" value="<?php echo $comment_author_email; ?/>" size="22" tabindex="2" < ?php if ($req) echo "aria-required='true'"; ?> /> 
<label for="email"><small>Mail (will not be published) < ?php if ($req) echo "(required)"; ?></small></label></p> 
 
<p><input type="text" name="url" id="url" value="<?php echo $comment_author_url; ?/>" size="22" tabindex="3" /> 
<label for="url"><small>Website</small></label></p>

2.将类以上代码替换成以下代码.

<!-- 有资料的访客 -->
<?php if ( $comment_author != "" ) : ?>
	<!--
		转换显示状态用的 JavaScript
		Q1: 为什么这段代码放在这里呢?
		A1: 因为只有当访客有资料时, 它才被用上, 这样可以减少无资料访客下载页面时的开销.
		Q2: 为什么不用外部文件将 JavaScript 放起来? 也许那样维护起来更方便.
		A2: 因为它只在这个地方用到了. 而且加载文件的数量也会影响页面下载速度, 为了这么点字节的代码, 不值得新开一个文件.
	-->
	<script type="text/javascript">function setStyleDisplay(id, status){document.getElementById(id).style.display = status;}</script>
	<div class="form_row small">
		<!-- 访客昵称 (随便欢迎一下) -->
		<?php printf(__('Welcome back <strong>%s</strong>.'), $comment_author) ?>
 
		<!-- 更改按钮 (点击后: 隐藏更改按钮, 显示取消按钮, 显示资料输入框) -->
		<span id="show_author_info"><a href="javascript:setStyleDisplay('author_info','');setStyleDisplay('show_author_info','none');setStyleDisplay('hide_author_info','');"><?php _e('Change &raquo;'); ?></a></span>
 
		<!-- 取消按钮 (点击后: 显示更改按钮, 隐藏取消按钮, 隐藏资料输入框) -->
		<span id="hide_author_info"><a href="javascript:setStyleDisplay('author_info','none');setStyleDisplay('show_author_info','');setStyleDisplay('hide_author_info','none');"><?php _e('Close &raquo;'); ?></a></span>
	</div>
<?php endif; ?>
 
<!-- 资料输入框 -->
<div id="author_info">
	<div class="form_row">
		<input type="text" name="author" id="author" value="<?php echo $comment_author; ?>" tabindex="1" />
		<label for="author" class="small"><?php _e('Name'); ?> <?php if ($req) _e('(required)'); ?></label>
	</div>
	<div class="form_row">
		<input type="text" name="email" id="email" value="<?php echo $comment_author_email; ?>" tabindex="2" />
		<label for="email" class="small"><?php _e('E-Mail (will not be published)');?> <?php if ($req) _e('(required)'); ?></label>
	</div>
	<div class="form_row">
		<input type="text" name="url" id="url" value="<?php echo $comment_author_url; ?>" tabindex="3" />
		<label for="url" class="small"><?php _e('Website'); ?></label>
	</div>
 
</div>
 
<!-- 有资料的访客 -->
<?php if ( $comment_author != "" ) : ?>
	<!-- 隐藏取消按钮, 隐藏资料输入框 -->
	<script type="text/javascript">setStyleDisplay('hide_author_info','none');setStyleDisplay('author_info','none');</script>
<?php endif; ?>
  • 3.搞定,局部可能受到缓存插件的影响,大家可以访问新的日志(未被WP Super Cache缓存).

是不是发现评论信息框的三个小框框已经没有了呢?

原创文章,转载请注明: 转载自Blinux

原文链接地址: 隐藏WordPress评论资料输入框

51 Responses to “隐藏WordPress评论资料输入框”

  1. 我的评论框一直都这样的阿。

    [回复]

    Blinux CHINA Internet Explorer Windows 回复:

    什么情况?
    1.柳城的blog的输入框支持隐藏
    2.柳城在Blinux blog上的评论框一直保持原样

    [回复]

    O型天蝎座 CHINA Internet Explorer Windows 回复:

    那当然是每一种。呵~~
    你修改后,现在的确是隐藏的了。

    [回复]

    Blinux CHINA Internet Explorer Windows 回复:

    不过我发现柳城的没有隐藏
    不知道怎么回事?
    :(

    [回复]

    Lc. CHINA Internet Explorer Windows 回复:

    恩。后来我也发现了~~ 原来是登陆用户才隐藏。 :???:

    [回复]

    Blinux CHINA Internet Explorer Windows 回复:

    :grin: 现在正常了

    [回复]

    Lc. CHINA Internet Explorer Windows 回复:

    拿了这段代码来用了嘛。。呵呵

    [回复]

    Blinux CHINA Internet Explorer Windows 回复:

    嘻嘻 :grin:

    [回复]

  2. zhukun CHINA Internet Explorer Windows 说:

    以前一直把网址输入框删掉了,因为怕有些人在博客上留下死链,呵呵。后来又恢复了,因为不想连是谁留的言都不知道

    [回复]

    Blinux CHINA Internet Explorer Windows 回复:

    总体还是留个比较好~

    [回复]

  3. liwen CHINA Internet Explorer Windows 说:

    很好啊~感觉wp用的人真不少!功能也很强大!

    [回复]

    Blinux CHINA Internet Explorer Windows 回复:

    这个应该和Firefox是同一个性质的产品

    [回复]

  4. CHINA Mozilla Firefox Windows 说:

    又是代码
    不想动了。。

    [回复]

    Blinux CHINA Internet Explorer Windows 回复:

    多活动,疏散筋骨 :)

    [回复]

  5. 巴黎春天 CHINA Mozilla Firefox Windows 说:

    改起来相当麻烦。因为曾经失败了。

    [回复]

    Blinux CHINA Mozilla Firefox Fedora Linux 回复:

    似乎只要将原来的几个输入框换的代码换成那段代码即可.

    [回复]

  6. 老饕 CHINA Mozilla Firefox Windows 说:

    ~~什么三个小框框啊

    [回复]

    Blinux CHINA Internet Explorer Windows 回复:

    就是经典的name、email、web.
    不过你的上面已经实现了这个效果。
    mg12

    [回复]

  7. SErHo CHINA Internet Explorer Windows 说:

    看见改代码就头疼,要是有插件就巴适了,呵呵

    [回复]

    Blinux CHINA Internet Explorer Windows 回复:

    其实我更喜欢修改代码,
    因为使用插件整体上是比修改代码要多占用一些资源 :)

    [回复]

  8. hiro CHINA Mozilla Firefox Windows 说:

    貌似下次访问,需要评论时,只需填写评论内容,而不用再填昵称、邮箱等!!

    [回复]

    Blinux CHINA Internet Explorer Windows 回复:

    哈哈,是这个意思~ :)

    [回复]

    liwen CHINA Internet Explorer Windows 回复:

    清空cookie后就有显示了吧:)

    [回复]

    Blinux CHINA Internet Explorer Windows 回复:

    是的 :)

    [回复]

  9. wanjie CHINA Mozilla Firefox Windows 说:

    用户体验不错,考虑那天情况时改一下。

    [回复]

    Blinux CHINA Internet Explorer Windows 回复:

    :lol:

    [回复]

  10. [...] 订阅RSS WordPress评论表情插件 « 隐藏WordPress评论资料输入框 [...]

  11. choubb CHINA Mozilla Firefox Windows 说:

    Bingo,你成功了

    [回复]

    Blinux CHINA Internet Explorer Windows 回复:

    是啊~
    :lol:

    [回复]

  12. iseeyou CHINA Mozilla Firefox Windows 说:

    好,我一会就改

    [回复]

    Blinux CHINA Internet Explorer Windows 回复:

    一会儿我帮您测试 :razz:

    [回复]

  13. [...] 开始没想改成这样,大家输入就输入了,就是两个个位数之和而已,反正也是访客麻烦,哈哈…现在用上了访客资料收缩(传送门:怎样实现这个功能呢?),不得不改成这样,不然有点麻烦。 [...]

  14. 小V CHINA Mozilla Windows 说:

    太酷了,这招学习了

    [回复]

    Blinux CHINA Internet Explorer Windows 回复:

    比较实用 :smile:

    [回复]

  15. likekart CHINA Internet Explorer Windows 说:

    现在在学校上网,到时候一定装上这个插件

    [回复]

    Blinux CHINA Internet Explorer Windows 回复:

    似乎可以提高用户体验 :lol:

    [回复]

  16. Lc. CHINA Internet Explorer Windows 说:

    哇哈哈。发现了好几处问题

    [回复]

    Blinux CHINA Mozilla Firefox Windows 回复:

    ls -l

    [回复]

    Lc. CHINA Internet Explorer Windows 回复:

    ll

    [回复]

    Blinux CHINA Internet Explorer Windows 回复:

    我没有看懂 :grin:

    [回复]

    Lc. CHINA Internet Explorer Windows 回复:

    哈哈。我也没看懂你的啊。
    如果是在linux下,ls -l 就是相当于用ll 啊 :lol:

    [回复]

    Blinux CHINA Internet Explorer Windows 回复:

    其实我的意思是让LC.列出“好几处问题” :grin:

    [回复]

    Lc. CHINA Internet Explorer Windows 回复:

    呵呵.还有这意思~~ < ?php应为<?php ,可能是复制的原因.
    'printf(__('Welcome back %s.'), $comment_author)'
    少了一个'
    '

    嘿~下载已到97%,早上出门前的数据~~ :mrgreen:

    [回复]

  17. 不会红太久 CHINA Google Chrome Windows 说:

    试试效果~呵呵 :roll:

    [回复]

  18. 不过你怎么不用?

    [回复]

    blinux AUSTRALIA Internet Explorer Windows 回复:

    谁说我没用 :oops:

    [回复]

  19. 色々なご事情で家族や恋人,友人にお勤め先を聞かれて返答できずに困った事やクレジットカードや入居等のお申し込みの際、水商売等の理由で会社名を記入出来なくて困った事の有る方へ在籍証明を登録し管理しているアリバイ会社です。
    もちろんこの会社は法務局に登記されている正式な法人会社です

    [回复]

Leave a Reply

:wink: :-| :-x :twisted: :) 8-O :( :roll: :-P :oops: :-o :mrgreen: :lol: :idea: :-D :evil: :cry: 8) :arrow: :-? :?: :!: