[英]Wordpress: Show up 'comment_form()' instead 'comment_reply_link()' in custom 'wp_list_comments()'
I'm developing my own code to display the comment list and comment form.我正在开发自己的代码来显示评论列表和评论表单。
What I need is to replace 'reply' button (only when is shown), with a comment form , next to the commentary to make the reply .我需要的是在评论旁边用评论表替换“回复”按钮(仅在显示时)以进行回复。
All the code I have so far is the following.到目前为止,我拥有的所有代码如下。 Can someone help me fix it?有人可以帮我解决吗? Thanks.谢谢。
<?php
$postid = XXX;
$comment_send = 'Send';
$comment_reply = 'Leave a Message';
$comment_reply_to = 'Reply';
$comment_author = 'Name';
$comment_email = 'E-Mail';
$comment_body = 'Comment';
$comment_url = 'Website';
$comment_cookies_1 = ' By commenting you accept the';
$comment_cookies_2 = ' Privacy Policy';
$comment_before = 'Registration isn\'t required.';
$comment_cancel = 'Cancel Reply';
$comments_args = array(
'fields' => array(
'author' => '<p class="comment-form-author"><br /><input id="author" name="author" aria-required="true" placeholder="' . $comment_author .'"></input></p>',
'email' => '<p class="comment-form-email"><br /><input id="email" name="email" placeholder="' . $comment_email .'"></input></p>',
'url' => '<p class="comment-form-url"><br /><input id="url" name="url" placeholder="' . $comment_url .'"></input></p>',
'cookies' => '<input type="checkbox" required>' . $comment_cookies_1 . '<a href="' . get_privacy_policy_url() . '">' . $comment_cookies_2 . '</a>',
),
'label_submit' => __( $comment_send ),
'title_reply' => __( $comment_reply),
'cancel_reply_link' => __( $comment_cancel ),
'comment_field' => '<p class="comment-form-comment"><br /><textarea id="comment" name="comment" aria-required="true" placeholder="' . $comment_body .'"></textarea></p>',
'comment_notes_before' => __( $comment_before),
'comment_notes_after' => ''
);
comment_form( $comments_args, $postid );
?>
<ol class="commentlist">
<?php wp_list_comments(array('callback' => 'custom_comments_format'), get_comments(array('post_id' => $post_id))); ?>
<?php function custom_comments_format($comment, $args, $depth){ ?>
<li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
<div id="comment-<?php comment_ID(); ?>">
<div class="comment-author">
<?php echo get_avatar( $comment, 56 ); ?>
<?php printf(__('<cite class="fn">%s</cite> <span class="says">says:</span>'), get_comment_author()) ?>
</div>
<div class="comment-moderation">
<?php if ($comment->comment_approved == '0') : ?>
<p><?php _e('Your comment is awaiting moderation.') ?></p>
<?php endif; ?>
</div>
<div class="comment-meta commentmetadata">
<p ><?php printf(__('%1$s at %2$s'), get_comment_date('j F, Y'), get_comment_time()) ?><?php edit_comment_link(__('(Edit)'),' ','') ?></p>
</div>
<div class="user-comment">
<?php comment_text() ?>
</div>
<div class="reply">
<?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
</div>
</div>
<?php } ?>
</ol>
Ps: The relation between a form and a reply comment is the comment_parent input. Ps:表单和回复评论之间的关系是comment_parent输入。 I can stack a new form instead the reply button, but I dont know how to set the comment_parent id into the comment_form( $comments_args, $postid ) ;我可以堆叠一个新表单而不是回复按钮,但我不知道如何将comment_parent id设置为comment_form( $comments_args, $postid ) ; as I did before to customize the form itself.就像我以前自定义表单本身一样。
<input type="hidden" name="comment_parent" id="comment_parent" value="XXX">
<div class="reply">
<?php //comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))); ?>
<?php
if($depth < $args['max_depth']){
$comments_args = array(
'comment_field' => '<input type=\'hidden\' name=\'comment_parent\' id=\'comment_parent\' value=\''.get_comment_ID().'\' />'
);
comment_form( $comments_args, $postid );
}
?>
</div>
Following my own steps, ive sloved the problem now its DONE like this.按照我自己的步骤,我已经解决了这个问题,现在它已经完成了。
<div class="reply">
<?php //comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))); ?>
<?php
if($depth < $args['max_depth']){
$postid = $comment->comment_post_ID;
$comments_args['submit_field'] = '<p class="form-submit"><input name="submit" type="submit" id="submit" class="submit" value="Send"> <input type="hidden" name="comment_post_ID" value="'.$postid.'" id="comment_post_ID"> <input type="hidden" name="comment_parent" id="comment_parent" value="'.get_comment_ID().'"> </p>';
comment_form( $comments_args, $postid );
}
?>
</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.