两种实现方法:
第一种:
完全自定义表单
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
<div class="add-comments" id="respond"> <h2 class="mb20">撰写评论</h2> <div class="alert alert-warning alert-dismissible" role="alert"> <span class="glyphicon glyphicon-bell"></span> <strong>注意:</strong><i>"评论内容</i>、<i>昵称</i>、<i>邮件地址"</i> 为必填项,邮件地址不会被公开。 </div> <?php comment_id_fields(); ?> <form id="commentform" name="commentform" action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" > <div class="form-group"> <label for="comment">评论内容</label> <p class="smiley"><?php include(TEMPLATEPATH . '/smiley.php'); ?></p> <textarea name="comment" rows="5" cols="" class="form-control" placeholder="输入评论内容" required="required"></textarea> </div> <div class="form-horizontal form-inline"> <div class="input-group mb10 col-lg-3"> <div class="input-group-addon"><span class="glyphicon glyphicon glyphicon-user"></span></div> <input id="author" name="author" aria-required="true" class="form-control" type="text" placeholder="昵称" required="required"> </div> <div class="input-group mb10 col-lg-3"> <div class="input-group-addon"><span class="glyphicon glyphicon-envelope"></span></div> <input id="email" name="email" aria-describedby="email-notes" aria-required="true" class="form-control" type="email" placeholder="邮箱" required="required"> </div> <div class="input-group mb10 col-lg-3"> <div class="input-group-addon"><span class="glyphicon glyphicon glyphicon-link"></span></div> <input id="url" name="url" class="form-control" type="url" placeholder="网址"> </div> <div class="input-group mb10 col-lg-2 col-xs-12"> <button type="submit" class="btn btn-primary btn-block"/>提交评论</button> <?php comment_id_fields(); ?> </div> </div> </form> </div> |
第二种:
使用内置函数
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
<?php comment_form( array( 'fields' => array( 'author' => ' <div class="form-horizontal"> <div class="input-group mb10 col-lg-12"> <div class="input-group-addon"><span class="glyphicon glyphicon glyphicon-user"></span></div> <input id="author" name="author" aria-required="true" class="form-control" type="text" placeholder="昵称" required="required" value="'.$comment_author.'"> </div> ', 'email' => ' <div class="input-group mb10 col-lg-12"> <div class="input-group-addon"><span class="glyphicon glyphicon-envelope"></span></div> <input id="email" name="email" aria-describedby="email-notes" aria-required="true" class="form-control" type="email" placeholder="邮箱" required="required" value="'.$comment_author_email.'" > </div> ', 'url' => ' <div class="input-group mb10 col-lg-12"> <div class="input-group-addon"><span class="glyphicon glyphicon glyphicon-link"></span></div> <input id="url" name="url" class="form-control" type="url" placeholder="网址" value="'.$comment_author_url.'" > </div> </div> ' ), 'label_submit'=>'提交回复', 'container_submit'=>'div', 'class_submit'=>'btn btn-primary btn-block', 'comment_field'=>' <div class="form-group"> <label for="comment" class="hidden">回复</label> <textarea id="comment" name="comment" rows="5" cols="" class="form-control" placeholder="输入回复内容" required="required"></textarea> </div> ', 'title_reply' => __( '<h2 class="mb20">发表评论</h2>' ), 'comment_notes_before' => '<p class="comment-notes">' . __( '<div class="alert alert-warning alert-dismissible" role="alert"> <span class="glyphicon glyphicon-bell"></span> <strong>注意:</strong><i>"评论内容</i>、<i>昵称</i>、<i>邮箱"</i> 为必填项,邮件地址不会被公开。 </div>' ) . ( $req ? $required_text : '' ) . '</p>', 'cancel_reply_link' => __( '<div class="btn btn-danger btn-xs col-xs-1 col-xs-offset-11">取消</div><div class="clearfix"></div>' ), 'logged_in_as' => '<p class="">' . sprintf( __( '已登陆为<a href="%1$s">%2$s</a> <a href="%3$s" title="注销">[注销]</a>' ), admin_url( 'profile.php' ), $user_identity, wp_logout_url( apply_filters( 'the_permalink', get_permalink( ) ) ) ) . '</p>', 'must_log_in' => '<p class="must-log-in">' . sprintf( __( ' <div class="alert alert-warning alert-dismissible" role="alert"> <span class="glyphicon glyphicon-bell"></span> <strong>注意:</strong>你需要<a href="%s">登陆</a>才能发表评论。<style>.smiley{display:none}</style> </div> ' ), wp_login_url( apply_filters( 'the_permalink', get_permalink() ) ) ) . '</p>', ) ); ?> |
内置函数使用说明可以参考这里,或者直接使用上面的代码。
文章评论 评论已关闭
评论已经关闭