• Resolved Sayontan Sinha

    (@sayontan)


    I am trying to enhance my theme and add support for threaded comments there. But this doesn’t seem to work. I followed the instructions at https://codex.www.ads-software.com/Migrating_Plugins_and_Themes_to_2.7/Enhanced_Comment_Display and made all the required changes:

    1. I put in the loop to use wp_list_comments() with the no extra parameters in my comments.php
    2. I added if ( is_singular() ) wp_enqueue_script( 'comment-reply' ); to my header.php, just above the call to wp_head()
    3. I added the call to comment_id_fields(); in my comments form.
    4. My comments textarea has ID = “comment”
    5. My comment form is enclosed in a div with ID = “respond”

    The following is the code for my comments.php file:

    <div id="comments-wrap">
    <?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">This post is password protected. Enter the password to view comments.</p>
    	<?php
    		return;
    	}
    ?>
    
    <!-- You can start editing here. -->
    <?php // Begin Comments & Trackbacks ?>
    <?php if ( have_comments() ) : ?>
    <h3 class="comments"><?php comments_number('No Comments', 'One Comments', '% Comments' );?> to “<?php the_title(); ?>”</h3>
    	<div class="navigation">
    		<div class="alignleft"><?php previous_comments_link() ?></div>
    		<div class="alignright"><?php next_comments_link() ?></div>
    	</div>
    
    <ul class="commentlist">
    	<?php
    	$commentargs = array(
    		"thread_comments_depth" => 5,
    		"avatar_size" => 48
    	);
    
    	wp_list_comments($commentargs);
    	?>
    </ul>
    	<div class="navigation">
    		<div class="alignleft"><?php previous_comments_link() ?></div>
    		<div class="alignright"><?php next_comments_link() ?></div>
    </div>
    <?php // End Comments ?>
    
     <?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><?php _e('Sorry, the comment form is closed at this time.'); ?></p>
    
    	<?php endif; ?>
    <?php endif; ?>
    
    <?php if ('open' == $post->comment_status) : ?>
    
    <div id="respond">
    
    <h3 class="respond"><?php comment_form_title( 'Leave a Reply', 'Leave a Reply to %s' ); ?></h3>
    
    <?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 action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" id="commentform">
    
    	<?php if ( $user_ID ) : ?>
    
    <p>Logged in as <a href="<?php echo get_option('siteurl'); ?>/wp-admin/profile.php"><?php echo $user_identity; ?></a>. <a href="<?php echo wp_logout_url(get_permalink()); ?>" title="Log out of this account">Log out &raquo;</a></p>
    
    	<?php else : ?>
    
    	<p>
    	<input type="text" name="author" id="author" class="textarea" value="<?php echo $comment_author; ?>" size="28" tabindex="1" />
    	<label for="author"><?php _e('Name'); ?></label> <?php if ($req) _e('(required)'); ?>
    	</p>
    
    	<p>
    	<input type="text" name="email" id="email" value="<?php echo $comment_author_email; ?>" size="28" tabindex="2" class="textarea" />
    	<label for="email"><?php _e('E-mail'); ?></label> <?php if ($req) _e('(required)'); ?>
    	</p>
    
    	<p>
    	<input type="text" name="url" id="url" value="<?php echo $comment_author_url; ?>" size="28" tabindex="3" class="textarea" />
    	<label for="url"><?php _e('<acronym title="Uniform Resource Identifier">URI</acronym>'); ?></label>
    	</p>
    
    	<?php endif; ?>
    
    	<p>
    	<label for="comment"><?php _e('Your Comment'); ?></label>
    	<br />
    	<textarea name="comment" id="comment" cols="60" rows="10" tabindex="4" class="textarea"></textarea>
    	</p>
    
    <div class="cancel-comment-reply">
    	<small><?php cancel_comment_reply_link(); ?></small>
    </div>
    
    	<p>
    	<?php comment_id_fields(); ?>
    	<input name="submit" id="submit" type="submit" tabindex="5" value="<?php _e('submit'); ?>" class="Cbutton" />
    	</p>
    	<?php do_action('comment_form', $post->ID); ?>
    </form>
    <?php endif; ?>
    </div>
    <?php else : // Comments are closed ?>
    <p><?php _e('Sorry, the comment form is closed at this time.'); ?></p>
    <?php endif; ?>
    </div>

    The following is the amendment in my header.php:

    <?php
    	if ( is_singular() ) wp_enqueue_script( 'comment-reply' );
    	wp_head();
    ?>

    And the following are the changes made in functions.php:

    // Begin legacy comments support
    add_filter( 'comments_template', 'legacy_comments' );
    function legacy_comments( $file ) {
    	if ( !function_exists('wp_list_comments') )
    		$file = TEMPLATEPATH . '/legacy-comments.php';
    	return $file;
    }
    //End legacy coments support

    I have ensured that nested comments are turned on from the settings page as well.

    Here is what happens:

    • I can see a “Reply” link for each comment. When I click on it the comment form moves right below it. So the Javascript is working.
    • When I post, however, the comment goes to the end of the list – the list is in the order of posting the comments. Also, the depth of the comments is always “depth-1”. See here: https://www.aquoid.com/sandbox/?p=188.
    • I switched to the WP default theme. The results are slightly different: when I post a response to a comment, the new comment shows up where it should, but I still get “depth-1” always, so there is no nesting.

    What could I be doing wrong?

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Threaded Comments Not Working’ is closed to new replies.