我正在编辑我的comments.php,并在其中添加了一个回复按钮,如下所示:
<div class="reply">
<a rel="nofollow" class="comment-reply-link"
href=<?php comment_reply_link(array('reply_text' => 'Reply this comment'), comment_ID()); ?> data-commentid="3"
data-postid="487" data-belowelement="div-comment-3" data-respondelement="respond"
data-replyto="Reply to admin" aria-label="Reply to admin"> Reply
</a>
</div>当我点击任何评论下的“回复”按钮时,第一个评论下面会弹出评论表单,并且只回复第一个评论,而不是我点击的那个。有人能解释这段代码中的错误并描述如何修复吗?
我也试着做
<div class="reply">
<?php comment_reply_link(); ?>
</div>但我相信,comment_reply_link()会返回null。
我列举的评论如下:
<?php
if (have_comments()) : ?>
<ol class="post-comments">
<?php
wp_list_comments(array(
'style' => 'ol',
'short_ping' => true,
'callback' => 'better_comments'
));
?>
</ol>
<?php
endif;并具有一个函数better_comments() {...},其中包含上述答复div的HTML。
下面是该函数的第一部分:
<li class="comment byuser comment-author-admin bypostauthor even thread-even depth-1" id="comment-3" style="margin-bottom: 0.7em;">
<div id="div-comment-3" class="comment-body">
<div class="comment-author vcard">
<a class="comment-author-text">
<b><?php echo ucwords(get_comment_author()) ?></b>
</a>谢谢。
发布于 2022-05-27 22:55:55
您的注释回复不起作用,因为您使用的是自定义注释呈现回调函数better_comments,并且这个函数硬编码类ID和其他属性,而不是调用函数(如comment_ID )。
我强烈建议放弃这个函数,而选择默认主题中的默认注释。这样,您就可以从一个已知的好解决方案开始,并以正确和递增的方式添加您想要的功能。
此外,您想要添加的许多内容不需要自定义的注释呈现器,例如,可以使用过滤器来更改应答链接文本,添加额外的链接也可以。
您还可能忘记将注释回复脚本排队:
// Threaded comment reply styles.
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}https://wordpress.stackexchange.com/questions/406157
复制相似问题