2016-08-22 92 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