2014-05-12 103 views
1

我一直在從頭開發一個自定義WordPress主題,並遇到了我的comments.php文件的一個小問題。WP評論沒有發佈正確

https://gist.github.com/phillipdews/dcebfec2016a93bd0169

我覺得從這個文件的第44行的問題,莖,當我試圖通過去發表在我的博客文章是否登陸,或者不在註釋流程:

www.mydomain.com/postlink/wp-comments-post.php 

當自然也需要到:

www.mydomain.com/wp-comments-post.php 

UPDATE

這就是我決定要做的!我又從頭開始,已經編寫了我的comments.php文件是這樣的:

<div id="comments"> 
    <?php if (post_password_required()) : ?> 
    <p>This post is password protected. Enter the password to view and comments</p> 
</div> 
<?php 
     return; 
    endif; 
?> 
<?php if (have_comments()) : ?> 
<ol> 
    <?php wp_list_comments (array('callback' => 'BRUM_Theme_comment')); ?> 
</ol> 
<?php 
    elseif (! comments_open() && ! is_page() && post_type_supports(get_post_type(), 'comments')) : 
?> 
<p>Comments are closed</p> 
<?php endif; ?> 
<?php comment_form(); ?> 
</div> 

我加入這個代碼片段到我的functions.php文件!這到目前爲止,我的評論顯示,人們也可以留言在我的博客文章!但到目前爲止,'回覆'按鈕不是正在渲染。

<?php 
function BRUM_Theme_comment($comment, $args, $depth){ 
    $GLOBALS['comment'] = $comment; 
    ?> 
    <?php if ($comment->comment_approved == '1'): ?> 
    <li> 
     <article id="comment-<?php comment_ID() ?>"> 
      <?php echo get_avatar($comment); ?> 
      <h4> 
       <?php comment_author_link() ?> 
      </h4> 
      <time><a href="#comment-<?php comment_ID() ?>" pubdate><?php comment_date() ?> at <?php comment_time() ?></a></time> 
      <?php comment_text() ?> 
     </article> 
     <?php endif; 
} 

就是這樣到目前爲止!一旦我得到了答覆按鈕的工作,我會修改代碼!

+1

嗨菲利普,如果您發現問題的解決方案隨時發佈您的解決方案作爲答案,然後接受它。 – themerlinproject

回答

1

試試這個:

<div id="respond"> 

<?php 

    if (!empty($_SERVER['SCRIPT_FILENAME']) && 'comments.php' == basename($_SERVER['SCRIPT_FILENAME'])) 
     die ('Please do not load this page directly. Thanks!'); 

    if (post_password_required()) { ?> 
     This post is password protected. Enter the password to view comments. 
    <?php 
     return; 
    } 
?> 

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

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

    <div class="navigation"> 
     <div class="next-posts"><?php previous_comments_link() ?></div> 
     <div class="prev-posts"><?php next_comments_link() ?></div> 
    </div> 

    <ol class="commentlist"> 
     <?php wp_list_comments(); ?> 
    </ol> 

    <div class="navigation"> 
     <div class="next-posts"><?php previous_comments_link() ?></div> 
     <div class="prev-posts"><?php next_comments_link() ?></div> 
    </div> 

<?php else : // this is displayed if there are no comments so far ?> 

    <?php if (comments_open()) : ?> 
     <!-- If comments are open, but there are no comments. --> 

    <?php else : // comments are closed ?> 
     <p>Comments are closed.</p> 

    <?php endif; ?> 

<?php endif; ?> 

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



    <h2><?php comment_form_title('Leave an reply', 'Leave a reply in %s'); ?></h2> 
    <div class="cancel-comment-reply"> 
     <?php cancel_comment_reply_link(); ?> 
    </div> 

    <?php if (get_option('comment_registration') && !is_user_logged_in()) : ?> 
     <p>You must be <a href="<?php echo wp_login_url(get_permalink()); ?>">logged in</a> to post a comment.</p> 
    <?php else : ?> 
<br class="c" /> 

    <form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" id="commentform"> 

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

      <p>Logged as <a href="<?php echo get_option('siteurl'); ?>/wp-admin/profile.php"><?php echo $user_identity; ?></a>. <a href="<?php echo wp_logout_url(get_permalink()); ?>" title="Log out of this account">Log out &raquo;</a></p> 

     <?php else : ?> 


      <div> 
       <input type="text" value="Name" onblur="if (this.value == '') {this.value = 'Name';}" onfocus="if (this.value == 'Name') {this.value = '';}" name="author" id="author" size="22" tabindex="1" <?php if ($req) echo "aria-required='true'"; ?> /> 
     </div> 

      <div> 
       <input type="text" value="Email" onblur="if (this.value == '') {this.value = 'Email';}" onfocus="if (this.value == 'Email') {this.value = '';}" name="email" id="email" size="22" tabindex="2" <?php if ($req) echo "aria-required='true'"; ?> /> 
      </div> 

      <div> 
       <input type="text" value="Website" onblur="if (this.value == '') {this.value = 'Website';}" onfocus="if (this.value == 'Website') {this.value = '';}" name="url" id="url" size="22" tabindex="3" /> 
      </div> 

     <?php endif; ?> 

<br /> 
     <div> 
      <textarea name="comment" id="comment" cols="58" rows="10" tabindex="4"></textarea> 
     </div> 
<br class="c" /> 
     <div> 

     <input name="submit" type="submit" id="submit" tabindex="5" value="Send" /> 
      <?php comment_id_fields(); ?> 
     </div> 

     <?php do_action('comment_form', $post->ID); ?> 

    </form> 

    <?php endif; // If registration required and not logged in ?> 

</div> 

<?php endif; ?> 

這可以解決任何的WordPress版本的問題,因爲3.1。 不要忘了把這段代碼放在你的模板文件夾中(comments.php)

1

這樣做了盧卡斯的工作夥伴!我不得不稍微調整一下代碼,然後從OL中刪除課程,並調整我的CSS,因爲它使得頭像變得非常大而且模糊!所以這是我做我的CSS代碼,以使評論風格的更好:

#respond {float: left;} 
#respond img {width: auto; height: auto; float: left; margin-right: 4px; border: 1px solid #aab59a; padding: 1px; border-radius: 10px;} 
#respond ol li { background: #f1f1f1; margin:10px 0;padding:8px;border:2px solid #ccc;font-style:normal;list-style: none; border-radius: 10px;} 

而且這是一個很好的功能,人們可以以自己的functions.php文件,因爲它使鏈接到回覆回覆以評論者的名字:

/* 
* Change the comment reply link to use 'Reply to &lt;Author First Name>' 
*/ 
function add_comment_author_to_reply_link($link, $args, $comment){ 

    $comment = get_comment($comment); 

    // If no comment author is blank, use 'Anonymous' 
    if (empty($comment->comment_author)) { 
     if (!empty($comment->user_id)){ 
      $user=get_userdata($comment->user_id); 
      $author=$user->user_login; 
     } else { 
      $author = __('Anonymous'); 
     } 
    } else { 
     $author = $comment->comment_author; 
    } 

    // If the user provided more than a first name, use only first name 
    if(strpos($author, ' ')){ 
     $author = substr($author, 0, strpos($author, ' ')); 
    } 

    // Replace Reply Link with "Reply to &lt;Author First Name>" 
    $reply_link_text = $args['reply_text']; 
    $link = str_replace($reply_link_text, 'Reply to ' . $author, $link); 

    return $link; 
} 

add_filter('comment_reply_link', 'add_comment_author_to_reply_link', 10, 3); 

希望別人覺得它有用,再次感謝它的工作出色!

+0

很好,很高興解決了菲利普的問題!隨意修改或改變任何你想要的方式。感謝您分享您的功能代碼! –

+0

一切都好!思考它我可以離開ol類,只是將它添加到我的css #respond> .commentlist ol li Just goto現在爲我的自定義主題做搜索表單,現在回到Wordpress Codex和github! –