gpt4 book ai didi

javascript - WordPress 回复评论链接

转载 作者:行者123 更新时间:2023-11-27 22:36:15 25 4
gpt4 key购买 nike

感觉我已经尝试了很多东西,所以我来这里寻求帮助。对别人有效的事情对我不起作用。我正在尝试嵌套评论,但我无法让它们发挥作用。我的情况很奇怪,因为回复评论表单显示在您尝试回复的评论下方,但是当您点击帖子时,它不起作用。另外,如果您查看 URL,它不会从 #comment-(某个值)更改为 #respond-(某个值)。我可以看到 js 已正确加载到我的 Chrome Inspector 选项卡中。我正在正确地将评论回复排入队列。

我尝试过以不同的方式对脚本进行排队,将我的永久链接重置为默认值,并进行了大量代码更改,但似乎没有任何效果。任何帮助将不胜感激。我尝试四处搜索,但未能找到解决方案或遇到类似问题的人。

[编辑]:我看不到 comment-reply.js 已正确加载到我的检查器选项卡中。我尝试通过将 blahblahblah 放置在 header.php 中的 wp_head 上方来强制加载,它加载了但没有效果。

这是我正在使用的代码及其所在的文件:

单.php:

<?php   

if( comments_open() ) {

comments_template();

}

?>


<?php endwhile;

endif;

?>

评论.php:

<?php if( have_comments() ): ?>

<h4 id="comments"><?php comments_number( 'No Comments', 'One Comment', '% Comments' ); ?></h4>

<ol class="commentlist">
<?php wp_list_comments(array(
'callback' => 'ericshio_custom_comments',
'max-depth' => 'x',
)); ?>
</ol>

<?php else : ?>

<p class="no-comments">No comments yet</p>

<?php endif; ?>

<?php

$comments_args = array(
// Change the title of send button
'label_submit' => __( 'Post', 'ericshio' ),
// Change the title of the reply section
'title_reply' => __( 'Write a Reply or Comment', 'ericshio' ),
);

?>

<?php comment_form($comments_args); ?>

函数.php:

/* Custom Comments */

function ericshio_enqueue_comments_reply() {
if( get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
}

add_action( 'comment_form_before', 'ericshio_enqueue_comments_reply' );

function ericshio_custom_comments($comment, $args, $depth) {
$GLOBALS[' comment '] = $comment; ?>
<li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
<div id="comment-<?php comment_ID(); ?>">
<div class="comment-author vcard">
<?php echo get_avatar($comment, $size='48', $default='<path_to_url>' ); ?>

<?php printf (__('<cite class="fn">%s</cite> <span class="says"> says:</span>'), get_comment_author_link()) ?>
</div>

<?php if ($comment->comment_approved == '0') : ?>
<em><?php _e('Your Comment is Awaiting Moderation.') ?> </em>
<br />
<?php endif ; ?>

<div class="comment-meta commentmetadata"><a href="<?php echo htmlspecialchars( get_comment_link($comment->comment_ID )) ?>"><?php printf(__('%1$s at %2$s'), get_comment_date(), get_comment_time() ) ?> </a> <?php edit_comment_link(__(' (Edit) '), ' ', ' ') ?> </div>

<div class="comment-wrapper">

<?php comment_text() ?>

<div class="reply">
<?php comment_reply_link(array_merge($args, array('depth' => $depth, 'max_depth' => $args['max_depth'] ))); ?>

</div>

</div>

</div>
<?php

}

最佳答案

你应该阅读这篇文章,因为过去我也遇到过同样的问题,所以我从这里解决了这个问题。

https://codex.wordpress.org/Template_Tags/wp_list_comments#Comments_Only_With_A_Custom_Comment_Display

引用:codex.wordpress.org

编辑:

header.php 中,添加此行 wp_head():

if ( is_singular() ) wp_enqueue_script( 'comment-reply' );

该代码将评论回复 JavaScript 添加到单个帖子页面。

因此,您的评论表单有一个必须添加的新参数:

<?php comment_id_fields(); ?>

<a id="respond"></a>

<h3><?php comment_form_title(); ?></h3>

这使得评论表单标题为“Leave a Reply”

<?php comment_form_title( 'Leave a Reply', 'Leave a Reply to %s' ); ?>

%s 将替换为该人的姓名。只有当 JavaScript 不工作时才会发生这种情况。

<div id="cancel-comment-reply">

<small><?php cancel_comment_reply_link() ?></small></div>

这些只是您需要使用的一般原则。

引用:OttoPress

关于javascript - WordPress 回复评论链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39070901/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com