• I have modified a theme and created the CSS file from scratch, and while everything is working fine, there is just one thing missing. The ‘Reply’ button that comes attached to every comment is not there. I checked everything, looked for answers everywhere, and still, no luck. ‘Nested Comments’ are enabled and the comment reply fix is evident in the functions.php file.

    I believe the problem lies within the HTML code that calls back the ‘reply’ action – I don’t know how to explain this better, but I hope you guys know what I mean.

    So, is there an HTML code that receives the call for a reply button? Something like < ?php comments reply> for example?

Viewing 9 replies - 1 through 9 (of 9 total)
  • Does your theme call comment_reply_link()?

    Thread Starter restlessness

    (@restlessness)

    I added it but nothing happens. Here’s the entire “comments.php” code:

    [ Moderator note: code fixed. Please wrap code in the backtick character or use the code button. ]

    <?php // Do not delete these lines
    	if ('comments.php' == basename($_SERVER['SCRIPT_FILENAME']))
    		die ('Please do not load this page directly. Thanks!');
    
    	if (!empty($post->post_password)) { // if there's a password
    		if ($_COOKIE['wp-postpass_' . COOKIEHASH] != $post->post_password) {  // and it doesn't match the cookie
    			?>
    
    			<p class="nocomments">This post is password protected. Enter the password to view comments.</p>
    
    			<?php
    			return;
    		}
    	}
    
    	/* This variable is for alternating comment background */
    	$oddcomment = 'class="alt" ';
    ?>
    
    <!-- You can start editing here. -->
    
    <?php if ($comments) : ?>
    	<h3 id="comments"><?php comments_number('No Comments Yet', 'One Comment', '% Comments' );?></h3>
    
    	<div class="commentbox">
    	<?php foreach ($comments as $comment) : ?>
    <h3 id="commenter"><b><?php comment_author_link() ?></b> | <?php comment_date('F jS, Y') ?> at <?php comment_time() ?></h3>
    
                            <?php if ($comment->comment_approved == '0') : ?>
    			<em>Your comment is awaiting moderation.</em>
    			<?php endif; ?>
    
    			<div id="commenttext"><?php comment_text() ?>
    <div id="reply"><?php comment_reply_link() ?></div>
    </div>
    
    	<?php
    		/* Changes every other comment to a different class */
    		$oddcomment = ( empty( $oddcomment ) ) ? 'class="alt" ' : '';
    	?>
    
    	<?php endforeach; /* end for each comment */ ?>
    </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) : ?>
    
    <h3 id="comments">Leave a Reply</h3>
    	<div class="commentbox">
    <?php if ( get_option('comment_registration') && !$user_ID ) : ?>
    <p>You must be <a>/wp-login.php?redirect_to=<?php the_permalink(); ?>">logged in</a> to post a comment.</p>
    <?php else : ?>
    <center>
    <form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" id="commentform">
    
    <?php if ( $user_ID ) : ?>
    
    <p>Logged in as <a>/wp-admin/profile.php"><?php echo $user_identity; ?></a>. <a>/wp-login.php?action=logout" title="Log out of this account">Logout ?</a></p>
    
    <?php else : ?>
    
    <p><label for="author">Name<?php if ($req) echo ""; ?> *</label>
    <input type="text" name="author" id="author" value="<?php echo $comment_author; ?>" size="56" tabindex="1" /></p>
    <p><label for="email">Email<?php if ($req) echo ""; ?> *</label>
    <input type="text" name="email" id="email" value="<?php echo $comment_author_email; ?>" size="56" tabindex="2" /></p>
    <p><label for="url">Website</label>
    <input type="text" name="url" id="url" value="<?php echo $comment_author_url; ?>" size="56" tabindex="3" />
    </p>
    
    <?php endif; ?>
    
    <!--<p><small><strong>XHTML:</strong> You can use these tags: <code><?php echo allowed_tags(); ?></code></small></p>-->
    
    <p>Comment
    <textarea name="comment" id="comment" cols="100%" rows="8" tabindex="4"></textarea></p>
    
    <p><input name="submit" type="submit" id="submit" tabindex="5" value="Submit" />
    <input type="hidden" name="comment_post_ID" value="<?php echo $id; ?>" />
    </p>
    <?php do_action('comment_form', $post->ID); ?>
    
    </form>
    </center>
    </div>
    <?php endif; // If registration required and not logged in ?>
    
    <?php endif; // if you delete this the sky will fall on your head ?>

    You need to pass max_depthto comment_reply_link() like so:

    comment_reply_link( 'depth' => 1, 'max_depth' => get_option( 'thread_comment_depth' ) );

    I realize that this is a bit counter-intuitive just from reading the Codex, but if you don’t call wp_list_comments() then certain arguments don’t get correctly passed to comment_reply_link(). Which brings me to my next point.

    I strongly recommend calling wp_list_comments() instead of using the foreach loop, mostly because of the above issue, but also because it’s easier to take advantage of the comment reply JS that moves the comment form right below the comment you’re replying to.

    Thread Starter restlessness

    (@restlessness)

    I’m a bit confused here…I’ve read about calling wp_list_comments(), and I’ve looked into all the themes I have – but they all operate with the foreach loop.

    If it’s not a lot of trouble, can you add that snippet into the code I posted and then re-posted? Thank you so much in advance!

    Can you post the name of one of your themes that uses the foreach loop to display comments? I’d like to see how they operate.

    Thread Starter restlessness

    (@restlessness)

    My current theme is “The Go Green Theme”, and some of the other installed themes are “Twenty Thirteen” and “Twenty Fourteen”.

    As I suspected, your current theme (Go Green) was last updated prior to the introduction of nested comments, so it’s not surprising that the comment reply link doesn’t work correctly. Rather than reinventing the wheel, I highly recommend using wp_list_comments() (as Twenty Thirteen and Twenty Fourteen do), which will handle nesting comments and the comment reply link for you.

    Thread Starter restlessness

    (@restlessness)

    Okay, so I’ve copied the entire comments.php file from the Twenty Fourteen theme and replaced it with my current (The Go Green) Theme – I tested it, and it worked! Thank you SO much!

    Right now the comments appear to be jumbled over each other and they lack proper padding/margins, so I how do I fix that and edit it them the way I did my previous comments file?

    For this level of coding, I’d recommend learning how to use Firebug. This page will help you out, but to get started, try this:

    .comment-list article {
    	padding-top: 20px;
    	margin-bottom: 24px;
    }
    
    .comment-list .children {
    	margin-left: 24px;
    }

    That will at least spread out the comments a bit so you can more easily use Firebug to see what selectors you need.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Adding a "Reply" button to comments’ is closed to new replies.