2016-08-22 93 views
1

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

我尝试了不同的排队脚本,将我的固定链接重置为默认值,以及无数的代码更改,但似乎无法获取任何内容。任何帮助将不胜感激。我尝试过四处搜寻,但一直未能找到解决方案或有类似问题的人。

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

这里是我使用的代码,它是在文件:

的single.php:

<?php 

     if(comments_open()) { 

       comments_template(); 

      } 

      ?> 


     <?php endwhile; 

    endif; 

?> 

的comments.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); ?> 

的functions.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 

} 
+1

这就是为什么我不碰的WordPress – Isaac

+0

哈哈哈,你用什么?:P – ERIC

+0

wordpress评论系统是荒谬怪异和复杂的。尤其对于我来说,因为我非常喜欢这个。此外,该法典没有提供有关此主题的更多信息,特别是与其他参考文献相比时。 – ERIC

回答

1

你应该阅读这个b因为过去同样的问题,所以我从这里解决了这个问题。

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> 

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

Refernce:OttoPress

+0

嘿,我已经读了很多次。究竟从它解决了你的问题? – ERIC

+1

你的主要问题是回复评论。对吗? – Noman

+0

是的,这是正确的:) – ERIC