【问题标题】:Wordpress Reply Comment LinkWordpress 回复评论链接
【发布时间】:2016-12-28 11:53:23
【问题描述】:

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

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

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

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

Single.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 

}

【问题讨论】:

  • 这就是我不碰wordpress的原因
  • 哈哈哈你用什么? :P
  • wordpress 评论系统非常奇怪和复杂。特别是对我来说,因为我在这一切方面都非常初学者。此外,该法典并未提供有关此主题的太多信息,尤其是与其他参考文献相比时。
  • 除了 wordpress 几乎没有任何东西

标签: javascript php wordpress nested comments


【解决方案1】:

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

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>

这使得评论表单标题为“留下回复”

<?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

【讨论】:

  • 嘿,我已经读了很多遍了。究竟是什么解决了您的问题?
  • 你的主要问题是回复评论。对吗?
  • 现在我使用与网站完全相同的代码,但它仍然无法正常工作:(可能我没有正确地将 js 排队,因为它没有显示在我的检查器选项卡中。
  • 等我给你答案。
  • 检查我的编辑版本。如果它解决了您的目的,请投票并接受答案。谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-13
  • 2017-09-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多