Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm using Greg's Threaded Comment Numbering plugin to number the comments. Actually I'm displaying a number beside of each parent comment (no threaded comments numbers). I have 2 problems that I have already tried to solve, but without results:

  • I am displaying the top comment with a different layout, I need to start the numbering from #2. seems an easy task but I didn't find the way modifying the plugin code.

  • Display the total number of threaded comments for each comment that has threads.

Example:

COMMENT 1

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

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

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

total threaded comments = 3

COMMENT 2

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

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

total threaded comments = 2

etc.....

I am already using the code below to get the total number of parents. I can also get the children but it is the total, I need to display the number of each comment children as in the example

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

Thanks!

EDIT: as requested here is the wp_list_comments callback function. Sorry for the mess, I am not a programmer, will clean the code when the work is finished :)

## 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
share|improve this question
    
Please post the code of your wp_list_comments( array( 'callback' => 'your_function' ) ); callback function. –  kaiser May 10 '11 at 17:12
    
thanks for the reply, posted the code as an edit. –  Andycap May 10 '11 at 17:19
add comment

1 Answer

up vote 2 down vote accepted
// 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 );
share|improve this answer
    
Thanks kaiser, tried but does not output anything. –  Andycap May 10 '11 at 21:38
    
@Andycap - Where exactly did you place that? It's close to what i use in my callback myself, so i know that it does work smoothly. Could you post your updated (and please: cleaned) callback function? Tante grazie! –  kaiser May 11 '11 at 9:42
    
Oh, and you need to replace TEXTDOMAIN with your textdomain string/constant/var or delete to avoid an ugly error. –  kaiser May 11 '11 at 9:53
    
Got it, thanks it's working! But maybe we had a misunderstanding: the code is counting each child, what I need is just to display the total number, example: "This comment has XX child comments". For ancestors: I need to count them but starting from 2 (ancestor + 1). Perhaps both could be solved modifying your code so I can get rid of the numbering plugin! Thanks –  Andycap May 13 '11 at 13:02
    
See update with init value and uncommented else. And please don't forget to vote and mark as solution if so. This will give you some pretty good karma :) –  kaiser May 13 '11 at 13:09
show 4 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.