• Hi there. I’m having a bit of an issue with my nested comments. I have just upgraded my comments.php to the new format with wp_list_comments() and all, and have put if ( is_singular() ) wp_enqueue_script( 'comment-reply' ); in my header.php, just above wp_head(). Everything should be good to go.

    But – no matter if I post comments or reply to them, the HTML output only assigns “depth-1” classes to my <li>s – not “depth-2”, “depth-3” and so on.

    This is my code:

    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.
    <?php
    		return;
    	}
    ?>
    
    <!-- You can start editing here. -->
    <div class="separator" style="margin-top: 20px; margin-bottom: 20px;"></div>
    
    <?php if ( have_comments() ) : ?>
    	<h3 id="comments"><?php comments_number('No Responses', 'One Response', '% Responses' );?> to “<?php the_title(); ?>”</h3>
    
    	<ol class="commentlist">
    	<?php wp_list_comments('type=comment&callback=custom_comments'); ?>
    	</ol>
    	<div class="navigation">
    		<div class="alignleft"><?php previous_comments_link() ?></div>
    		<div class="alignright"><?php next_comments_link() ?></div>
    	</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">Comments are closed.</p>
    
    	<?php endif; ?>
    <?php endif; ?>
    
    <?php if ('open' == $post->comment_status) : ?>
    
    <div id="respond">
    
    <h1 style="font-size: 20px;"><?php comment_form_title( 'Skriv en kommentar', 'Skriv en kommentar til %s' ); ?></h1>
    
    <div class="cancel-comment-reply">
    	<small><?php cancel_comment_reply_link(); ?></small>
    </div>
    
    <?php if ( get_option('comment_registration') && !$user_ID ) : ?>
    <p>You must be <a href="<?php echo get_option('siteurl'); ?>/wp-login.php?redirect_to=<?php echo urlencode(get_permalink()); ?>">logged in</a> to post a comment.</p>
    <?php else : ?>
    
    <form class="comment_wrapper" action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" id="commentform">
    
    <?php if ( is_user_logged_in() ) : ?>
    
    <ul>
    	<li class="onethird">
    		<div style="margin-bottom: 10px;"><?php printf(__('Logged in as %s.'), '<a href="'.get_option('siteurl').'/wp-admin/profile.php">'.$user_identity.'</a>'); ?> | <?php wp_loginout(); ?></div>
    	</li>
    
    <?php else : ?>
    
    <ul>
    	<li class="onethird">
    		<div style="border: 0px solid;"> <!-- IE7 HACK -->
    			<input class="input" type="text" name="author" id="author" title="Navn" value="<?php echo esc_attr($comment_author); ?>" size="22" tabindex="1" />
    			<div class="form_title">Navn<span class="req"> *</span></div>
    			<input class="input" type="text" name="email" id="email" title="Email" value="<?php echo esc_attr($comment_author_email); ?>" size="22" tabindex="2" />
    			<div class="form_title">Email (offentligg&oslash;res ikke)<span class="req"> *</span></div>
    			<input class="input" type="text" name="url" id="url" title="WWW" value="<?php echo esc_attr($comment_author_url); ?>" size="22" tabindex="3" />
    			<div class="form_title">WWW</div>
    		</div>
    
    		<div id="recaptcha_widget">
    			<input type="text" id="recaptcha_response_field" name="recaptcha_response_field" />
    			<div class="form_title">Skriv nedenst&aring;ende to ord<span class="req"> *</span></div>
    			<div id="recaptcha_image"></div>
    			<div class="reload_captcha"><a href="javascript:Recaptcha.reload()"></a></div>
    			<div class="recaptcha_only_if_audio"><a href="javascript:Recaptcha.switch_type('image')"></a></div>
    			<div class="recaptcha_only_if_image"><a href="javascript:Recaptcha.switch_type('audio')"></a></div>
    			<div class="help"><a href="javascript:Recaptcha.showhelp()"></a></div>
    			<div class="cleaner"></div>
    			<div class="comments_tip">Tip! For at undg&aring; reCAPTCHA-udfordringen n&aring;r du kommenterer blogindl&aelig;g, musik og webdesign, kan du registrere dig som bruger. <?php wp_register('', ''); ?></div>
    			<div class="comments_tip">Tip 2! Hvis du vil vise et billede sammen med din kommentar, kan du oprette en <a class="liexternal" href="https://www.gravatar.com/">Gravatar</a>.</div>
    		</div>
    	</li>
    
    <?php endif; ?>
    
    	<li class="twothirds">
    		<div style="border: 0px solid;"> <!-- IE7 HACK -->
    			<textarea class="commentform_input" name="comment" id="comment" cols="0" rows="0" tabindex="4"></textarea>
    			<div class="form_title">Kommentar<span class="req"> *</span></div>
    			<div class="form_title"><span class="req">Felter markeret med * SKAL udfyldes.</span></div>
    			<input class="submit" name="submit" type="submit" id="submit" tabindex="5" value="" title="Send" />
    			<input type="hidden" name="comment_post_ID" value="<?php echo $id; ?>" />
    			<?php do_action('comment_form', $post->ID); ?>
    		</div>
    
    	</li>
    </ul>
    <div class="cleaner"></div>
    </form>
    
    <?php endif; // If registration required and not logged in ?>
    
    <?php else : // Comments are closed ?>
    <p><?php _e('Sorry, the comment form is closed at this time.'); ?></p>
    <?php endif; ?>

    And since I’m using a custom wp_list_comments(), this is what I have defined in my theme’s functions.php:

    function custom_comments($comment, $args, $depth) {
    	$GLOBALS['comment'] = $comment; ?>
    	<li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
    		<div id="comment-<?php comment_ID(); ?>">
    		<div class="comment_text_wrapper"><a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ?>"></a>
    			<?php comment_text() ?>
    			<div class="reply">
    				<?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
    			</div>
    			<?php edit_comment_link(__('Edit'),'  ','') ?>
    			<?php if ($comment->comment_approved == '0') : ?>
    			<em><?php _e('Your comment is awaiting moderation.') ?></em>
    			<?php endif; ?>
    		</div>
    		<div class="comment_author_wrapper">
    			<?php echo get_avatar($comment,$size='32',$default='<path_to_url>' ); ?>
    			<?php printf(__('%s'), get_comment_author_link()) ?>
    			<?php printf(__('<div class="datetime">%1$s at %2$s</div>'), get_comment_date(),  get_comment_time()) ?>
    		</div>
    	  <div class="cleaner"></div>
    
    	<div class="separator" style="margin-top: 20px; margin-bottom: 20px;"></div>
         </div>
    <?php }
    ?>

    Any idea what the problem might be? You can test it out for yourself at my site: https://www.psylicium.dk/blog/2009/12/23/sa-er-vi-flyttet (I hope this is allowed ??

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Nested comments – only “depth-1” classes are assigned’ is closed to new replies.