我目前正在开发自己的 Wordpress 主题,并且最近一直在开发自定义 comments_template();
.我读过使用wp_list_comments();
方法是引入和显示每页/帖子评论的最佳实践。我已经成功地自定义了通过该方法提取和显示评论的方式。
我也读过使用 comment_form();
方法是显示评论表单的最佳实践。但是,我真的很难尝试自定义它。我对 $args、过滤器 和操作 有点困惑。
本质上,我想彻底改变评论表单的某些部分。我如何才能改变部分评论表单,同时仍然使用 comment_form();
的最佳实践?方法?
我真正需要做的就是包装几个现有的 <p>
<divs>
中的标签.我尝试进行的更新列表如下:
- 调整
<h3>
标题为<h2 class="comments-header">Tell us about you!</h2>
- 在
<fieldset></fieldset>
中包装表单字段 - 换行
<label>
在<div class="label"></div>
- 换行
<input>
在<div class="field"></div>
- 制作
<p class="form-allowed-tags"></p>
在评论之前显示<textarea>
而不是之后 - 更改表单提交按钮以使用
<button>
元素而不是<input>
请查看下面的代码以获得进一步的解释...
默认comment_form();输出代码:
<div id="respond">
<h3 id="reply-title">Leave a Reply</h3>
<form action="http://localhost/.../wp-comments-post.php" method="post" id="commentform">
<p class="comment-notes">
Your email address will not be published. Required fields are marked
<span class="required">*</span>
</p>
<p class="comment-form-author">
<label for="author">Name</label>
<span class="required">*</span>
<input id="author" name="author" type="text" value="John Doe" size="30" aria-required="true">
</p>
<p class="comment-form-email">
<label for="email">Email</label>
<span class="required">*</span>
<input id="email" name="email" type="text" value="johndoe@dodgeit.com" size="30" aria-required="true">
</p>
<p class="comment-form-url">
<label for="url">Website</label>
<input id="url" name="url" type="text" value size="30">
</p>
<p class="comment-form-comment">
<label for="comment">Comment</label>
<textarea id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea>
</p>
<p class="form-allowed-tags">
You may use these HTML tags and attributes...
</p>
<p class="form-submit">
<input name="submit" type="submit" id="submit" value="Post Comment">
<input type="hidden" name="comment_post_ID" value="22" id="comment_post_ID">
<input type="hidden" name="comment_parent" id="comment_parent" value="0">
</p>
</form>
</div> <!-- #respond -->
我尝试输出的代码:
<div id="respond">
<h2 class="comments-header">Tell us about you!</h2>
<form action="http://localhost/.../wp-comments-post.php" method="post" id="commentform">
<fieldset>
<div class="label"><label for="author">Name <span class="required">*</span></label></div>
<div class="field"><input id="author" name="author" type="text" value="<?php echo $comment_author_email; ?>" size="30" aria-required="true"></div>
</fieldset>
<fieldset>
<div class="label"><label for="email">E–mail (will not be published) <span class="required">*</span></label></div>
<div class="field"><input id="email" name="email" type="text" value="<?php echo $comment_author_email; ?>" size="30" aria-required="true"></div>
</fieldset>
<p class="form-allowed-tags">
You may use these HTML tags and attributes...
</p>
<fieldset>
<div class="field"><textarea id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea></div>
</fieldset>
<p class="form-submit">
<button class="story-submit-btn" type="submit" name="submit" id="sub">Post your story</button>
<input type="hidden" name="comment_post_ID" value="<?php echo $id; ?>" id="comment_post_ID">
<input type="hidden" name="comment_parent" id="comment_parent" value="0">
</p>
</form>
</div> <!-- #respond -->
非常感谢任何帮助!
最佳答案
如何更改一些评论表单字段的简单示例。
$comments_args = array(
// change the title of send button
'label_submit'=>'Send',
// change the title of the reply section
'title_reply'=>'Write a Reply or Comment',
// remove "Text or HTML to be displayed after the set of comment fields"
'comment_notes_after' => '',
// redefine your own textarea (the comment body)
'comment_field' => '<p class="comment-form-comment"><label for="comment">' . _x( 'Comment', 'noun' ) . '</label><br /><textarea id="comment" name="comment" aria-required="true"></textarea></p>',
);
comment_form($comments_args);
关于php - 如何自定义 Wordpress comment_form();,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11333810/