Numerar comentarios en plantilla sin foreach

  • Autor Autor MartyMcFly
  • Fecha de inicio Fecha de inicio

MartyMcFly

Dseda
Verificación en dos pasos activada
Verificado por Whatsapp
Buenas,

¿Como puedo numerar los comentarios en mi plantilla? Normalmente lo hago facil porque hay un foreach por ahi, y con una variable que voy incrementando, se muestra el numero de comentario sin problemas, pero en una plantilla que estoy tocando, no hay ningun foreach.

Os copio el código donde se muestran los comentarios, y en rojo el lugar donde me gustaria que apareciese el numero de comentario, que es así como lo hago otras veces, pero en esta plantilla no puedo hacerlo asi.

¿Alguna idea?

Insertar CODE, HTML o PHP:
<?php { function arras_list_comments($comment, $args, $depth) {
	$GLOBALS['comment'] = $comment;?> 
	<li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
	   <div class="comment-node" id="comment-<?php comment_ID(); ?>">
	      <div class="comment-controls">
	         <?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
	      </div>
	   <div class="comment-author vcard">
    	      <?php echo get_avatar($comment, $size = 60) ?>
	      <cite class="fn"><?php echo [COLOR="red"]$numComentario++;[/COLOR] ?>. <?php echo get_comment_author_link() ?></cite>
	   </div>
	   <?php if ( $comment->comment_approved == '0' ) : ?>
	   <span class="comment-moderation"><?php _e('Su comentario está pendiente de moderación. Gracias!', 'arras') ?></span>	
	   <?php endif; ?>
	   <div class="comment-meta commentmetadata">
	      <?php printf( __(' %1$s a las %2$s', 'arras'), '<abbr class="comment-datetime">' . get_comment_time( __('j F Y', 'arras') ), get_comment_time( __('G:i', 'arras') ) . '</abbr>' ); ?>
	   </div>
           <div class="comment-content"><?php comment_text() ?></div>
	   </div>
	</li>
<?php } ?>
 
Última edición:
pues por ser una función puedes pasar por parámetro el número del contador o declararlo como global..

para global te quedaría así:

PHP:
<?php 
$numComentario=0;
{ function arras_list_comments($comment, $args, $depth) {
       global $numComentario;
	$GLOBALS['comment'] = $comment;?> 
	<li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
	   <div class="comment-node" id="comment-<?php comment_ID(); ?>">
	      <div class="comment-controls">
	         <?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
	      </div>
	   <div class="comment-author vcard">
    	      <?php echo get_avatar($comment, $size = 60) ?>
	      <cite class="fn"><?php echo $numComentario++; ?>. <?php echo get_comment_author_link() ?></cite>
	   </div>
	   <?php if ( $comment->comment_approved == '0' ) : ?>
	   <span class="comment-moderation"><?php _e('Su comentario está pendiente de moderación. Gracias!', 'arras') ?></span>	
	   <?php endif; ?>
	   <div class="comment-meta commentmetadata">
	      <?php printf( __(' %1$s a las %2$s', 'arras'), '<abbr class="comment-datetime">' . get_comment_time( __('j F Y', 'arras') ), get_comment_time( __('G:i', 'arras') ) . '</abbr>' ); ?>
	   </div>
           <div class="comment-content"><?php comment_text() ?></div>
	   </div>
	</li>
<?php } ?>