• Resolved doppiar

    (@doppiar)


    Hi! πŸ™‚

    I’m going crazy: can you help me with my comments template? I want to show the background of my comments with alternate background colors, but something sounds like if some comments are not viewed as odd or even (it’s like if comments even or odd are in wrong places!)

    This is my comments.php code

    <?php
    
    // 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"><?php _e('This post is password protected. Enter the password to view comments.','mythemeshop'); ?></p>
    <?php
    return;
    }
    ?>
    
    <!-- You can start editing here. -->
    
    <?php if ( have_comments() ) : ?>
    	<div id="comments">
    		<h3><?php comments_number(__('No Responses','mythemeshop'), __('One Response','mythemeshop'),  __('% Comments','mythemeshop') );?></h3>
     			<ol class="commentlist clearfix">
    				<div class="navigation">
    					<div class="alignleft"><?php previous_comments_link() ?></div>
    					<div class="alignright"><?php next_comments_link() ?></div>
    				</div>
    <div class="avv"><em><strong>Nota:</strong> Per rispondere a un singolo commento, clicca la fascetta blu che trovi nell'angolo sinistro!</em></div>
    
    				<?php wp_list_comments('type=all&callback=mts_comments'); ?>
    
    				<div class="navigation">
    					<div class="alignleft"><?php previous_comments_link() ?></div>
    					<div class="alignright"><?php next_comments_link() ?></div>
    				</div>
    			</ol>
    		</div>
    <?php else : // this is displayed if there are no comments so far ?>
    <?php if ('open' == $post->comment_status) : ?>
    <!-- If comments are open, but there are no comments. -->
    <?php else : // comments are closed ?>
    <!-- If comments are closed. -->
    <p class="nocomments"></p>
    <?php endif; ?>
    <?php endif; ?>
    
    <?php if ('open' == $post->comment_status) : ?>
    	<div id="commentsAdd">
    		<div id="respond" class="<?php 
    
       if ($comment->comment_parent>0) {
          echo('boxreplica');
       } else {
          echo('box m-t-6');
       }
    ?>">
    			<?php global $aria_req; $comments_args = array(
    					'title_reply'=>'<h3>'.__('Add a Comment','mythemeshop').'</h3>',
    					'comment_notes_after' => '',
    					'label_submit' => __( 'Add Comment', 'mythemeshop' ),
    					'comment_field' => '<p class="comment-form-comment"><textarea id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea></p>',
    					'fields' => apply_filters( 'comment_form_default_fields',
    						array(
    							'author' => '<p class="comment-form-author">'
    							.'<label style="display:none" for="author">'. __( 'Name', 'mythemeshop' ).'<span class="required"></span></label>'
    							.( $req ? '' : '' ).'<input id="author" name="author" type="text" placeholder="'.__('Name','mythemeshop').'" value="'.esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /></p>',
    						'email' => '<p class="comment-form-email"><label style="display:none" for="email">' . __( 'Email', 'mythemeshop' ) . '<span class="required"></span></label>'
    							.($req ? '' : '' ) . '<input id="email" name="email" type="text" placeholder="'.__('Email','mythemeshop').'" value="' . esc_attr(  $commenter['comment_author_email'] ).'" size="30"'.$aria_req.' /></p>',
    						'url' => '<p class="comment-form-url"><label style="display:none" for="url">' . __( 'Website', 'mythemeshop' ).'</label>' .
    						'<input id="url" name="url" type="text" placeholder="'.__('Website','mythemeshop').'" value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" /></p>'
    					) )
    			);
    			comment_form($comments_args); ?>
    		</div>
    	</div>
    <?php endif; // if you delete this the sky will fall on your head ?>

    And this is my callback in functions.php

    function mts_comments($comment, $args, $depth) {
    	$GLOBALS['comment'] = $comment; ?>
    	<li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
    <div id="comment-<?php comment_ID(); ?>" style="text-align:justify;">
          <div class="<?php 
    
       if ($comment->comment_parent>1) {
          echo('nest2');
       } else {
          echo('comment-author');
       }
    ?>">
             <div id="avatarneicommenti" <?php 
    
       if ($comment->comment_parent>1) {
          echo('class="nest"');
       }
    ?>><?php echo get_avatar($comment,$size='80',$default='http://www.ilgiomba.it/wp-content/themes/onepage/images/avdefb.png' ); ?></div>
    
    		 <strong style="color:#0000B3!important;"><?php printf(__('%s'), get_comment_author_link()) ?></strong> <?php comment_date('l j F Y') ?> alle ore <?php comment_time() ?> <?php 
    
       if ($comment->comment_parent>1) {
          echo('<strong>ha risposto</strong>');
       } else {
          echo('<strong>ha scritto</strong>');
       }
    ?>:
          </div>
          <?php if ($comment->comment_approved == '0') : ?>
             <em><?php _e('Il tuo commento &egrave; in attesa di essere analizzato: sar&agrave; online non appena vagliato!') ?></em>
             <br />
          <?php endif; ?>
    
          <div class="<?php 
    
       if ($comment->comment_parent>1) {
          echo('nest3');
       } else {
          echo('.commentlist p');
       }
    ?>"><?php comment_text() ?></div>
    
         <div class="ang"><span id="angsp" style="<?php 
    
       if ($comment->comment_parent>1) {
          echo('display:none;');
       }
    ?>"><?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth'], 'reply_text' => 'RISPONDI'))) ?></span></div>
    
    </div>
    
    <?php }

    I’m going crazy, after a week without a solution! Please help me! Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Odd/Even class for alternate background color comments not working’ is closed to new replies.