Get threaded comments number

时间:2011-05-10 作者:Andycap

我正在使用Greg的线程化评论编号插件对评论进行编号。实际上,我在每个父注释旁边显示了一个数字(没有线程注释数字)。我已经尝试解决了两个问题,但都没有结果:

我正在用不同的布局显示顶部注释,我需要从#2开始编号。看起来很容易,但我没有找到修改插件代码的方法。

显示每个具有线程的注释的线程注释总数。

示例:

评论1

------------1.1

------------1.2

------------1.3

总线程注释数=3

评论2

------------2.1

------------2.2

总线程注释数=2

我已经在使用下面的代码来获取家长总数。我也可以得到子项,但它是总数,我需要显示每个注释子项的数量,如示例所示

$number_of_parents = c_parent_comment_counter($post->ID);
$number_of_children = $post->comment_count - $number_of_parents;
谢谢!

编辑:根据请求,这里是wp\\u list\\u comments回调函数。抱歉弄得一团糟,我不是程序员,工作完成后会清理代码:)

## Function: Basic Callback Function From WP Codex (http://codex.wordpress.org/Template_Tags/wp_list_comments), January 2009
function gtcn_basic_callback($comment, $args, $depth) {
// no changes here except that we have added in the call to gtcn_comment_numbering
   $GLOBALS[\'comment\'] = $comment; 


   ?>
   <li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
   <?php   if( empty( $comment->comment_parent ) ) { //if the comment does not have a parent, then it is L1?>
            <div class="linguetta-posizione"><?php  echo gtcn_comment_numbering($comment->comment_ID, $args); 

            ?></div>        
                <?php   }
         ?>

     <div id="comment-<?php comment_ID(); ?>">
      <div class="comment-author vcard">
        <div class="comment-barra-user">

            <div class="comment-avatar">
            <?php if( empty( $comment->comment_parent ) ) { ?><?php echo get_avatar($comment,$size=\'60\'); ?><?php } else { ?><?php echo get_avatar($comment,$size=\'30\'); ?><?php } ?></div>
            <div class="comment-username"><?php printf((\'<cite class="fn">%s</cite> \'), get_comment_author_link()) ?><br class="clear"/>
                <?php if( empty( $comment->comment_parent ) ) { ?><div id="comment-container-points">
                    <div class="comment-points"><img src="<?php bloginfo(\'template_url\'); ?>/images/ico-points.png" /><a>3333</a></div><div class="comment-level"><img src="<?php bloginfo(\'template_url\'); ?>/images/ico-level.png" /><a>livello</a></div>
                </div>      <?php } else { ?><?php } ?>         
            </div>
            <?php if ( is_user_logged_in() ) { if( empty( $comment->comment_parent ) ) {?>
            <div class="comment-votazione"><h2>Vota la risposta:</h2>

            <?php    { //if the comment does not have a parent, then it is L1
                    if(function_exists(ckrating_display_karma)) { ckrating_display_karma(); }
                    }
         ?> </div>
            <?php }} else { 

                if( empty( $comment->comment_parent ) ) { ?>
                <div class="comment-votazione"><h2>Registrati per votare</h2>

                 </div>
            <?php }}  ?> 


        </div><!-- end BARRA USER -->

    <br class="clear"/>

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


      <?php comment_text() ?>

      <div class="reply">
         <?php comment_reply_link(array_merge( $args, array(\'reply_text\' => \'COMMENTA LA RISPOSTA\', \'depth\' => $depth, \'max_depth\' => $args[\'max_depth\']))) ?>
      </div><div class="comment-meta commentmetadata"><?php if( empty( $comment->comment_parent ) ) { ?>Risposta inserita<?php } else { ?> Commento inserito <?php } ?>
            <?php echo time_ago_comment(); ?><?php edit_comment_link((\'- modifica\'),\'  \',\'\') ?></div>

     </div></li>

<?php
} // end basic callback function

1 个回复
最合适的回答,由SO网友:kaiser 整理而成
// inside your callback function:
static $ancestors = null;
$parent = (int) $comment->comment_parent;

// Modify INITIAL VALUE here:
$init_val = (int) 1;

$is_child = false;
if ( $parent > (int) 0 )
{
    $is_child = true;
    $ancestors[] = $parent;
    $child_counter = count( $ancestors ) + $init_val;
}
/*
 * Only needed in case you want to reset the counter if the current comment has no children
else
{
    $ancestors = $child_counter = null;
}
*/

// This shows the number of the current reply counter
if ( $is_child ) 
    printf( __( \'This is the child number: \', TEXTDOMAIN ), $child_counter );
结束

相关推荐

Comments Confusion

网站:【已删除】如果你转到上面的帖子,你会看到有一些评论,这些评论在发布时出于某种原因显示为管理员评论。如果您在查找特定评论时遇到问题,您也可以按CTRL+F组合键,使用下面的单词Test comment或Guest来查找它,这是我出于测试目的发布在这里的。问题是,它通过将管理员图像放在评论的右侧,使来宾用户的评论显示为管理员评论。奇怪的是,只有当用户回复管理员评论时才会发生这种情况:o有人能帮忙告诉我是什么导致了这种行为吗?我对wordpress主题开发非常陌生:(提前谢谢。