admin管理员组文章数量:1296922
I've been searching high and low for this but can't find anything that explains how to add custom fields to only the reply form. I've seen and got working custom fields on the comment form, but when a user clicks reply, I want to have a different set of fields. Better still a different set of fields depending on the reply level.
Here’s what I’m trying to do.
Suppose you have a site which posts a blog entry that you want people to post reviews and comments as a first level comment. I’d add a custom field for the first level comment with the options (radio button or drop down): “Review”, “Comment”. That's easy enough to do and well documented.
Then for 2nd level replies I want people to be post a comment that says whether they agree or disagree with that review and why, or just make a comment, so I want add a field to second level replies that has the options: “Agree”, “Disagree”, “Comment”, but the custom field on the first level comment (with "Reivew", "Comment") should not be displayed. This is what I can't figure out or find any tips on nor can I find any hooks/filters that allow you to access the reply form.
I looked at this question (that seems similar) but couldn't figure out what was done and so can't tell if it's a solution: Customize reply form different to comment form
Any help greatly appreciated.
I've been searching high and low for this but can't find anything that explains how to add custom fields to only the reply form. I've seen and got working custom fields on the comment form, but when a user clicks reply, I want to have a different set of fields. Better still a different set of fields depending on the reply level.
Here’s what I’m trying to do.
Suppose you have a site which posts a blog entry that you want people to post reviews and comments as a first level comment. I’d add a custom field for the first level comment with the options (radio button or drop down): “Review”, “Comment”. That's easy enough to do and well documented.
Then for 2nd level replies I want people to be post a comment that says whether they agree or disagree with that review and why, or just make a comment, so I want add a field to second level replies that has the options: “Agree”, “Disagree”, “Comment”, but the custom field on the first level comment (with "Reivew", "Comment") should not be displayed. This is what I can't figure out or find any tips on nor can I find any hooks/filters that allow you to access the reply form.
I looked at this question (that seems similar) but couldn't figure out what was done and so can't tell if it's a solution: Customize reply form different to comment form
Any help greatly appreciated.
Share Improve this question edited Apr 13, 2017 at 12:37 CommunityBot 1 asked Dec 19, 2014 at 7:33 MohibMohib 311 silver badge2 bronze badges 1- Ever get this figured out? I'm trying to do something similar. – CragMonkey Commented Mar 28, 2018 at 23:56
2 Answers
Reset to default 1By using comment_form( $args, $post_id )
you can add extra field in your comment form like this
$commenter = wp_get_current_commenter();
$req = get_option( 'require_name_email' );
$aria_req = ( $req ? " aria-required='true'" : '' );
$fields = array(
'author' => '<p class="comment-form-author">' . '<label for="author">' . __( 'Name' ) . '</label> ' . ( $req ? '<span class="required">*</span>' : '' ) .
'<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /></p>',
'email' => '<p class="comment-form-email"><label for="email">' . __( 'Email' ) . '</label> ' . ( $req ? '<span class="required">*</span>' : '' ) .
'<input id="email" name="email" type="text" value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /></p>',
);
$comments_args = array(
'fields' => $fields
);
comment_form($comments_args);
also Customizing Comments fields
We can even add fields to the comment for using the 'comment_form_default_fields' filter. add this in function. We can add a field as follows:
function add_comment_fields($fields) {
$fields['age'] = '<p class="comment-form-age"><label for="age">' . __( 'Age' ) . '</label>' .
'<input id="age" name="age" type="text" size="30" /></p>';
return $fields;
}
add_filter('comment_form_default_fields','add_comment_fields');
#respond ment-form-author label,
#respond ment-form-email label,
#respond ment-form-url label,
#respond ment-form-age label,
#respond ment-form-comment label {
background: #eee;
-webkit-box-shadow: 1px 2px 2px rgba(204,204,204,0.8);
-moz-box-shadow: 1px 2px 2px rgba(204,204,204,0.8);
box-shadow: 1px 2px 2px rgba(204,204,204,0.8);
color: #555;
display: inline-block;
font-size: 13px;
left: 4px;
min-width: 60px;
padding: 4px 10px;
position: relative;
top: 40px;
z-index: 1;
}
Reference url
本文标签: How to add custom comment fields but *only on the comment reply form*
版权声明:本文标题:How to add custom comment fields but *only on the comment reply form*? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741642555a2390001.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论