以下是HTML–
<!-- Comment Form HTML -->
<div class="sub-figure">
<div class="sub-post-title">
<h4 class="recent-title">Comments</h4>
</div>
</div>
<!-- Leave a comment -->
<div class="sub-figure">
<div class="sub-post-title">
<h4 class="recent-title">Leave A Comment</h4>
</div>
<form class="form-inline">
<div class="col-xs-12 col-sm-4 col-md-4 form-group">
<input type="text" class="form-control height-in" id="reply-name" placeholder="Enter Name">
</div>
<div class="col-xs-12 col-sm-4 col-md-4 form-group">
<input type="email" class="form-control height-in" id="replay-email" placeholder="Enter Email">
</div>
<div class="col-xs-12 col-sm-12 col-md-12 form-group top-equal">
<textarea class="form-control" rows="7" placeholder="Comment"></textarea>
</div>
<div class="col-xs-12 col-sm-12 col-md-12 form-group top-equal">
<input type="submit" class="btn btn-1 btn-1a ct-us-send">
</div>
</form>
</div>
<!-- Comments List HTML -->
<div class="comment-details">
<div class="comment-pic">
<img src="img/comment.jpg">
</div>
<div class="comment-inner">
<div class="comment-info">
<div class="clearfix">
<h4>Vajrasar</h4>
<a href="#"><i class="fa fa-reply"></i> Reply</a>
</div>
<div class="comment-on">
<h6>September 9, 2014</h6>
</div>
<div class="comment-text">
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
</div>
</div>
</div>
</div>
以下是我用来输出修改后的注释表单的代码–
<?php
//Disabling URL field
function vg_disable_comment_url( $fields ) {
unset( $fields[\'url\'] );
return $fields;
}
add_filter(\'comment_form_default_fields\',\'vg_disable_comment_url\');
//To edit defaults in comment field
function vg_modify_comment_defaults( $defaults ) {
$defaults[\'comment_notes_after\'] = \'\';
$defaults[\'comment_notes_before\'] = \'\';
$defaults[\'title_reply\'] = \'Leave A Comment\';
$defaults[\'comment_field\'] = \'\';
return $defaults;
}
add_filter( \'comment_form_defaults\', \'vg_modify_comment_defaults\' );
//To modify structure of input fields and the wrapping html markup
function vg_modify_comment_form_fields( $fields ){
$fields[\'author\'] = \'<div class="col-xs-12 col-sm-4 col-md-4 form-group">\'
. \'<input class="form-control height-in" placeholder="Enter Name" id="author" name="author" type="text" value="\'
. esc_attr( $commenter[\'comment_author\'] )
. \'" size="30"\'
. $aria_req
. \' /></div>\';
$fields[\'email\'] = \'<div class="col-xs-12 col-sm-4 col-md-4 form-group">\'
. \'<input class="form-control height-in" placeholder="Enter Email" id="email" name="email" \'
. ( $html5 ? \'type="email"\' : \'type="text"\' )
. \' value="\'
. esc_attr( $commenter[\'comment_author_email\'] )
. \'" size="30"\'
. $aria_req
. \' /></div>\';
$fields[\'comment_field\'] = \'<div class="col-xs-12 col-sm-12 col-md-12 form-group top-equal">
<textarea class="form-control" placeholder="Comment" id="comment" name="comment" cols="45" rows="7" aria-required="true"></textarea>
</div>\';
$fields[\'comment_notes_after\'] = \'<input type="submit" class="btn btn-1 btn-1a ct-us-send" id="submit-new" value="\' . __( \'Submit\' ) . \'" />\';
return $fields;
}
add_filter(\'comment_form_default_fields\',\'vg_modify_comment_form_fields\');
以下内容将取代默认注释列表调用注释。WP本机主题文件中的php-
wp_list_comments( \'type=comment&callback=vg_format_comment\' ); //vg_format_comment is the function being called
以下是输出修改注释列表的代码–
//To modify comment list and its wrapping markup using vg_format_comment function defined in callback
function vg_format_comment( $comment, $args, $depth ) {
$GLOBALS[\'comment\'] = $comment;
$ca = get_comment_author();
?>
<div class="comment-details">
<div class="comment-pic">
<?php echo get_avatar( $comment, 32 ); ?>
</div>
<div class="comment-inner">
<div class="comment-info">
<div class="clearfix">
<h4><?php printf(__(\'%s\'), get_comment_author_link()) ?></h4>
<div id="reply-cover">
<i class="fa fa-reply"></i> <?php comment_reply_link(array_merge( $args, array(\'depth\' => $depth, \'max_depth\' => $args[\'max_depth\']))) ?>
</div>
</div>
<div class="comment-on">
<h6><?php printf(__(\'%1$s\'), get_comment_date(), get_comment_time()) ?></h6>
</div>
<div class="comment-text">
<?php comment_text(); ?>
</div>
</div>
</div>
</div>
<div class="clearfix"></div>
<?php
}
以下是我用来为WP输出的注释表单提供自定义类的内容-
// To add custom class in comment form in comment.php in wp native themes
ob_start();
comment_form();
echo str_replace(\'class="comment-form"\',\'class="form-inline"\',ob_get_clean()); //class added is form-inline