admin管理员组文章数量:1024945
EDIT I am trying to change the class and id of the <form>
element and well as the <input>
/Submit button field using the comment_form()
function. How ever it appears that various string values are being echoed out instead of replacing the default values (see demo link).
CODE:
<?php if ( comments_open() ) : ?>
<?php
$req = get_option( 'require_name_email' );
$aria_req = ( $req ? ' aria-required="true"' : '' );
$fields = array(
'id_form' => 'comment-form',
'class_form' => 'form-inline',
'class_submit' => 'btn btn-default',
'author' => '<div class="form-group">
<label for="comment-author" class="sr-only">' . __( 'Author', 'magneton' ) . '</label>
<input type="text" name="author" id="comment-author" class="form-control" placeholder="' . __( 'Author (required)', 'magneton' ) . '"' . $aria_req . '>',
'email' => '<label for="comment-author-email" class="sr-only">' . __( 'E-Mail', 'magneton' ) . '</label>
<input type="email" name="email" id="comment-author-email" class="form-control" placeholder="' . __( 'E-Mail (required)', 'magneton' ) . '"' . $aria_req . '>',
'url' => '<label for="comment-author-url" class="sr-only">' . __( 'Website', 'magneton' ) . '</label>
<input type="url" name="url" id="comment-author-url" class="form-control" placeholder="' . __( 'Website'. 'magneton' ) . '">
</div>'
);
$comments_args = array(
'fields' => $fields,
'title_reply' => __( 'Leave a reply', 'magneton' ),
'comment_field' => '<textarea name="comment" id="comment" class="form-control" aria-required="true" rows="10"></textarea>',
'label_submit' => __( 'Submit Comment', 'magneton' )
);
?>
<?php comment_form( $comments_args ); ?>
<?php endif; ?>
LINK: DEMO
EDIT I am trying to change the class and id of the <form>
element and well as the <input>
/Submit button field using the comment_form()
function. How ever it appears that various string values are being echoed out instead of replacing the default values (see demo link).
CODE:
<?php if ( comments_open() ) : ?>
<?php
$req = get_option( 'require_name_email' );
$aria_req = ( $req ? ' aria-required="true"' : '' );
$fields = array(
'id_form' => 'comment-form',
'class_form' => 'form-inline',
'class_submit' => 'btn btn-default',
'author' => '<div class="form-group">
<label for="comment-author" class="sr-only">' . __( 'Author', 'magneton' ) . '</label>
<input type="text" name="author" id="comment-author" class="form-control" placeholder="' . __( 'Author (required)', 'magneton' ) . '"' . $aria_req . '>',
'email' => '<label for="comment-author-email" class="sr-only">' . __( 'E-Mail', 'magneton' ) . '</label>
<input type="email" name="email" id="comment-author-email" class="form-control" placeholder="' . __( 'E-Mail (required)', 'magneton' ) . '"' . $aria_req . '>',
'url' => '<label for="comment-author-url" class="sr-only">' . __( 'Website', 'magneton' ) . '</label>
<input type="url" name="url" id="comment-author-url" class="form-control" placeholder="' . __( 'Website'. 'magneton' ) . '">
</div>'
);
$comments_args = array(
'fields' => $fields,
'title_reply' => __( 'Leave a reply', 'magneton' ),
'comment_field' => '<textarea name="comment" id="comment" class="form-control" aria-required="true" rows="10"></textarea>',
'label_submit' => __( 'Submit Comment', 'magneton' )
);
?>
<?php comment_form( $comments_args ); ?>
<?php endif; ?>
LINK: DEMO
Share Improve this question edited May 4, 2017 at 20:25 Frederick M. Rogers asked May 4, 2017 at 17:54 Frederick M. RogersFrederick M. Rogers 1352 silver badges10 bronze badges 3 |1 Answer
Reset to default 1Those classes are being rendered inline because the id_form
, class_form
, and class_submit
parameters should be placed within the $comments_args
array (alongside title_reply
, comment_field
, etc) and not within the $fields
array. See comment_form().
Also one last question, is there any way to re-arrange the order of the fields?
Yes, the fields can be reordered. Here's an answer that shows how to accomplish reordering and customizing the comment fields. The main gotcha with reordering the comment fields is that if you want the main comment field to appear above the name/email/URL/etc fields, the comment_form_defaults
filter needs to be used to set $comment_field
to an empty string. This is because of how the parameters are set up; $comment_field
is special and not part of the $fields
array by default. This is covered in the answer linked above.
EDIT I am trying to change the class and id of the <form>
element and well as the <input>
/Submit button field using the comment_form()
function. How ever it appears that various string values are being echoed out instead of replacing the default values (see demo link).
CODE:
<?php if ( comments_open() ) : ?>
<?php
$req = get_option( 'require_name_email' );
$aria_req = ( $req ? ' aria-required="true"' : '' );
$fields = array(
'id_form' => 'comment-form',
'class_form' => 'form-inline',
'class_submit' => 'btn btn-default',
'author' => '<div class="form-group">
<label for="comment-author" class="sr-only">' . __( 'Author', 'magneton' ) . '</label>
<input type="text" name="author" id="comment-author" class="form-control" placeholder="' . __( 'Author (required)', 'magneton' ) . '"' . $aria_req . '>',
'email' => '<label for="comment-author-email" class="sr-only">' . __( 'E-Mail', 'magneton' ) . '</label>
<input type="email" name="email" id="comment-author-email" class="form-control" placeholder="' . __( 'E-Mail (required)', 'magneton' ) . '"' . $aria_req . '>',
'url' => '<label for="comment-author-url" class="sr-only">' . __( 'Website', 'magneton' ) . '</label>
<input type="url" name="url" id="comment-author-url" class="form-control" placeholder="' . __( 'Website'. 'magneton' ) . '">
</div>'
);
$comments_args = array(
'fields' => $fields,
'title_reply' => __( 'Leave a reply', 'magneton' ),
'comment_field' => '<textarea name="comment" id="comment" class="form-control" aria-required="true" rows="10"></textarea>',
'label_submit' => __( 'Submit Comment', 'magneton' )
);
?>
<?php comment_form( $comments_args ); ?>
<?php endif; ?>
LINK: DEMO
EDIT I am trying to change the class and id of the <form>
element and well as the <input>
/Submit button field using the comment_form()
function. How ever it appears that various string values are being echoed out instead of replacing the default values (see demo link).
CODE:
<?php if ( comments_open() ) : ?>
<?php
$req = get_option( 'require_name_email' );
$aria_req = ( $req ? ' aria-required="true"' : '' );
$fields = array(
'id_form' => 'comment-form',
'class_form' => 'form-inline',
'class_submit' => 'btn btn-default',
'author' => '<div class="form-group">
<label for="comment-author" class="sr-only">' . __( 'Author', 'magneton' ) . '</label>
<input type="text" name="author" id="comment-author" class="form-control" placeholder="' . __( 'Author (required)', 'magneton' ) . '"' . $aria_req . '>',
'email' => '<label for="comment-author-email" class="sr-only">' . __( 'E-Mail', 'magneton' ) . '</label>
<input type="email" name="email" id="comment-author-email" class="form-control" placeholder="' . __( 'E-Mail (required)', 'magneton' ) . '"' . $aria_req . '>',
'url' => '<label for="comment-author-url" class="sr-only">' . __( 'Website', 'magneton' ) . '</label>
<input type="url" name="url" id="comment-author-url" class="form-control" placeholder="' . __( 'Website'. 'magneton' ) . '">
</div>'
);
$comments_args = array(
'fields' => $fields,
'title_reply' => __( 'Leave a reply', 'magneton' ),
'comment_field' => '<textarea name="comment" id="comment" class="form-control" aria-required="true" rows="10"></textarea>',
'label_submit' => __( 'Submit Comment', 'magneton' )
);
?>
<?php comment_form( $comments_args ); ?>
<?php endif; ?>
LINK: DEMO
Share Improve this question edited May 4, 2017 at 20:25 Frederick M. Rogers asked May 4, 2017 at 17:54 Frederick M. RogersFrederick M. Rogers 1352 silver badges10 bronze badges 3-
1
Move the
id_form
,class_form
, andclass_submit
items out of$fields
and into the$comments_args
array (alongsidetitle_reply
,comment_field
, etc). Seecomment_form()
. – Dave Romsey Commented May 4, 2017 at 20:33 - 1 @DaveRomsey, thank i looked over the documentation (again) and you are correct. I swear sometime i get so blind looking at code. You should make this an answer so i can check it off. Also one last question, is there any way to re-arrange the order of the fields? – Frederick M. Rogers Commented May 5, 2017 at 17:21
- Thank you! I've added an answer and linked to another solution that covers rearranging and customizing the comment form fields. – Dave Romsey Commented May 5, 2017 at 18:58
1 Answer
Reset to default 1Those classes are being rendered inline because the id_form
, class_form
, and class_submit
parameters should be placed within the $comments_args
array (alongside title_reply
, comment_field
, etc) and not within the $fields
array. See comment_form().
Also one last question, is there any way to re-arrange the order of the fields?
Yes, the fields can be reordered. Here's an answer that shows how to accomplish reordering and customizing the comment fields. The main gotcha with reordering the comment fields is that if you want the main comment field to appear above the name/email/URL/etc fields, the comment_form_defaults
filter needs to be used to set $comment_field
to an empty string. This is because of how the parameters are set up; $comment_field
is special and not part of the $fields
array by default. This is covered in the answer linked above.
本文标签: comment formcommentform() Not changing the default classid of elements
版权声明:本文标题:comment form - comment_form() Not changing the default classid of elements 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745499447a2153320.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
id_form
,class_form
, andclass_submit
items out of$fields
and into the$comments_args
array (alongsidetitle_reply
,comment_field
, etc). Seecomment_form()
. – Dave Romsey Commented May 4, 2017 at 20:33