kaf*_*der 5 html php wordpress comments wordpress-theming
我目前正在开发自己的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>
请参阅以下代码以获得进一步说明......
<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 -->
Run Code Online (Sandbox Code Playgroud)
<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 -->
Run Code Online (Sandbox Code Playgroud)
任何帮助是极大的赞赏!
如何更改某些评论表单字段的简单示例。
$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);
Run Code Online (Sandbox Code Playgroud)
有关更多信息:WordPress Codex 上的 comment_form() 文档
我用来functions.php
修改评论显示。我不知道这是否是现在做事的方式(我使用 WP 开发的最后一个网站并需要评论是在 2009 年;)),但它是(将其放入文件中functions.php
!:
function THEMENAME_comment($comment, $args, $depth) {
$GLOBALS['comment'] = $comment;
*your comment display code*
}
Run Code Online (Sandbox Code Playgroud)
记得还要创建 pingback 主题。您的操作与注释类似,唯一的区别是第一行:
函数 THEMENAME_pings($comment, $args, $deep)
其他方式可能是使用comments_template。