我目前正在开发自己的 Wordpress 主题,并且最近一直在开发自定义comments_template();
. 我已经读过,使用该wp_list_comments();
方法是拉入和显示每页/帖子的评论的最佳实践。我已经成功地自定义了通过该方法拉入并显示评论的方式。
我还读到使用该comment_form();
方法是显示评论表单的最佳实践。但是,我真的很难尝试自定义它。我对$args、filters和actions有点困惑。
本质上,我想彻底改变评论表单的部分内容。在仍然使用该方法的最佳实践的同时,我如何着手更改评论表单的部分内容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 -->
任何帮助是极大的赞赏!