2012-05-30 33 views
2

我嘗試創建一個WordPress主題,我有幾個問題。WordPress,評論回覆是根據最後的消息,而不是根據回覆的評論

我tryed到用戶的comment_reply_link但沒有在所有的工作,我deside通過添加代碼manualy創建鏈接如下:

<?php 
    $permalink = get_permalink() . "?replytocom=" . get_comment_ID() . "#comments-form"; 
    $onclick = "return addComment.moveForm('comment-" . get_comment_ID() . "', '" . get_comment_ID() . "', 'comments-form', '" . get_the_ID() . "')"; 
?> 
<a href="<?php echo $permalink; ?>" onclick="<?php echo $onclick; ?>"> 
    <?php _e('Reply', 'z'); ?> 
</a> 

而且我已經排隊的評論回覆,並加載正常。

我的自定義回覆鏈接工作正常。當我點擊回覆鏈接時,表單會移動到我的評論下方,但在我提交我的評論後,答覆不會置於已回覆的評論之下,而是位於評論結尾處。

注意:在我的評論的形式我輸入以下代碼:

<input type='hidden' name='comment_post_ID' value='<?php the_ID(); ?>' id='comment_post_ID' /> 
<input type='hidden' name='comment_parent' id='comment_parent' value='0' /> 

,並使用Chrome的控制檯,我看到現場comment_parent值更新到回覆評論ID

+1

我想弄明白這一點! :( Killrawr

回答

2

好吧,我真的不知道如何才能幫助您解決您的問題,但我可以爲您提供一些指導,幫助您完善我的自定義評論模板! 我使用ThemeShaper http://themeshaper.com/2009/07/01/wordpress-theme-comments-template-tutorial/的Ian Stewart教程製作我的評論模板。 首先,文件的comments.php看起來就像是:

<?php 
/** 
* @package WordPress 
* @subpackage Default_Theme 
*/ 

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

    if (post_password_required()) { ?> 
     <p class="nocomments">This post is password protected. Enter the password to view comments.</p> 
    <?php 
     return; 
    } 
?> 

<!-- You can start editing here. --> 

<?php if (have_comments()) : ?> 
    <h3 id="comments"><?php comments_number('No hay Respuestas', 'Hay 1 Respuesta', 'Hay % Respuestas');?></h3> 

    <ol class="commentlist"> 
     <?php wp_list_comments('type=comment&callback=advanced_comment'); //this is the important part that ensures we call our custom comment layout defined above 
       ?> 
    </ol> 
    <div class="clear"></div> 
    <div class="comment-navigation"> 
     <div class="older"><?php previous_comments_link() ?></div> 
     <div class="newer"><?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 ?> 
     <!-- If comments are closed. --> 
     <p class="nocomments">Los comentarios están cerrados.</p> 

    <?php endif; ?> 
<?php endif; ?> 


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

<div id="respond"> 

<h3><?php comment_form_title('Comentar', 'Responder %s'); ?></h3> 

<div class="cancel-comment-reply"> 
    <small><?php cancel_comment_reply_link(); ?></small> 
</div> 

<?php if (get_option('comment_registration') && !is_user_logged_in()) : ?> 
<p>Debes iniciar sesión para poder comentar.</p> 
<a href="http://dfine.me?loginGoogle=1&redirect=http://dfine.me" onclick="window.location = 'http://dfine.me?loginGoogle=1&redirect='+window.location.href; return false;"><div class="new-google-btn new-google-3 new-google-default-anim"><div class="new-google-3-1"><div class="new-google-3-1-1">Iniciar Sesión</div></div></div></a> 
<a href="http://dfine.me?loginFacebook=1&redirect=http://dfine.me" onclick="window.location = 'http://dfine.me?loginFacebook=1&redirect='+window.location.href; return false;"><div class="new-fb-btn new-fb-3 new-fb-default-anim"><div class="new-fb-3-1"><div class="new-fb-3-1-1">Iniciar Sesión</div></div></div></a> 

<?php else : ?> 

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

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

<p>Sesión iniciada por <a href="<?php echo get_option('siteurl'); ?>/wp-admin/profile.php"><?php echo $user_identity; ?></a>. <br><a href="<?php echo wp_logout_url(get_permalink()); ?>" title="Cerrar sesión">Cerrar sesión &raquo;</a></p> 

<?php else : //this is where we setup the comment input forums ?> 


<?php endif; ?> 

<!--<p><small><strong>XHTML:</strong> You can use these tags: <code><?php echo allowed_tags(); ?></code></small></p>--> 


<p><textarea name="comment" id="comment" cols="90%" rows="10" tabindex="4"></textarea></p> 

<p><input name="submit" type="submit" id="submit" tabindex="5" value="Post" /> 
<?php comment_id_fields(); ?> 
</p> 
<?php do_action('comment_form', $post->ID); ?> 

</form> 

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

<?php endif; // if you delete this the sky will fall on your head ?> 

我改變了登錄節,因爲我用的是下一頁末頁連接Facebook和谷歌插件。 中的functions.php的功能:

function advanced_comment($comment, $args, $depth) { 
    $GLOBALS['comment'] = $comment; ?> 

<li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>"> 
    <div class="comment-author vcard"> 
    <?php echo get_avatar($comment,$size='90',$default='<path_to_url>'); ?> 
    <small class="comment-date"><?php printf(__('%1$s at %2$s'), get_comment_date(), get_comment_time()) ?></small>  
    <div class="comment-meta"<a href="<?php the_author_meta('user_url'); ?>"><?php printf(__('%s'), get_comment_author_link()) ?></a> dice:<?php edit_comment_link(__('(Edit)'),' ','') ?></div> 
    </div> 
    <div class="clear"></div> 

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

    <div class="comment-text"> 
     <?php comment_text() ?> 
     <div class="reply"> 
     <?php comment_reply_link(array_merge($args, array('depth' => $depth, 'max_depth' => $args['max_depth'], 'login_text' => "Responder"))) ?> 
     <?php delete_comment_link(get_comment_ID()); ?> 
    </div> 
    </div> 
    <div class="clear"></div> 
<?php } 

這:

function delete_comment_link($id) { 
    if (current_user_can('edit_post')) { 
    echo '- <a href="'.admin_url("comment.php?action=cdc&c=$id").'"> Eliminar</a> '; 
    echo '- <a href="'.admin_url("comment.php?action=cdc&dt=spam&c=$id").'"> Spam</a>'; 
    } 
} 

而且,我做一些小的修改,以核心帶註釋的template.php添加圖像旁邊的「回覆」鏈接。 comment-template.php:

if (get_option('comment_registration') && !$user_ID) 
     $link = '<a rel="nofollow" class="comment-reply-login" href="' . esc_url(wp_login_url(get_permalink())) . '"><img src="' . $direccion_sitio . '/images/reply.png" alt="Responder" style="margin-right:5px;">' . $login_text . '</a>'; 
    else 
     $link = "<a class='comment-reply-link' href='" . esc_url(add_query_arg('replytocom', $comment->comment_ID)) . "#" . $respond_id . "' onclick='return addComment.moveForm(\"$add_below-$comment->comment_ID\", \"$comment->comment_ID\", \"$respond_id\", \"$post->ID\")'><img src='" . $direccion_sitio . "/images/reply.png' alt='Responder' style='margin-right:5px;'>$reply_text</a>"; 
    return apply_filters('comment_reply_link', $before . $link . $after, $args, $comment, $post); 

最後,CSS!

/*Comentarios*/ 
.comments-template{ 
    width: 730px; 
    display: inline-block; 
    margin: 10px 0; 
    padding-top: 20px; 
    border-top: 3px dotted #CCC; 
} 

#comments{ 
    padding-bottom: 10px; 
    border-bottom: 1px solid #EEE; 
} 

.commentlist{ 
    margin: 15px 0; 
} 

.comment-meta{ 
    padding: 5px 10px 1px 0; 
    border-bottom: 1px dashed lightGrey; 
    margin-bottom: 5px; 
    display: inline-block; 
} 

.comment-meta .url{ 
    font-family: 'Franklin Gothic Book Italic', sans-serif; 
    font-size: 1.1em; 
    font-weight: 700; 
} 

.comment-text{ 
    padding: 5px 0 35px 0; 
    min-height: 65px; 
    position: relative; 
    border-bottom: 1px solid #EEE; 
    margin-bottom: 10px; 
} 
.comment-date{ 
    display: block; 
    padding-top: 5px; 
    font-size: 0.7em; 
    color: #7E7E7E; 
    font-style: italic; 
} 
.comments-template .avatar-90{ 
    float: left; 
    padding: 5px 15px 10px 0; 
} 
.reply{ 
    position: absolute; 
    bottom: 10px; 
    right: 10px; 
} 
.depth-2{ 
    margin-left: 105px; 
} 
.depth-3{ 
    margin-left: 210px; 
} 
#respond{ 
    margin-bottom: 30px;  
} 
/*Fin Comentarios*/ 

如果我得到它的權利,你的主要問題是回答一個特別的評論沒有顯示正確,所以也許你需要看看你的CSS的,在我的情況,.depth類。

如果您想測試我的自定義評論模板,您可以訪問http://dfine.me並評論任何帖子中的任何內容。我在Wordpress偏好設置中的配置是隻允許1個嵌套註釋。 希望這有助於! PS:對混合'英語 - 西班牙語'的聲明抱歉...