前几天在其它BLOG见到一个相当实用的评论功能. 即:访客留言之后资料输入框会被隐藏起来, 如同登录了一般. 访客可以选择修改相关资料再进行评论. 给予访客很好的用户体验.

经过网络学习和久酷风云帮助,成功在自己的评论上应用了这个功能!

废话不多,直接贴出代码:(具体含义请看:提高 WordPress 访客评论时的用户体验

<!-- 有资料的访客 -->
<?php if ( $comment_author != "" ) : ?>
	<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">
	<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>
 
	<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>
 
	<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>
 
<!-- 有资料的访客 -->
<?php if ( $comment_author != "" ) : ?>
	<script type="text/javascript">setStyleDisplay('hide_author_info','none');setStyleDisplay('author_info','none');</script>
<?php endif; ?>

需要的朋友把这段代码放到comments.php相关位置即可!当然,本站已经实现了,不妨留言试试哦~