• I can’t seem to get comments to work on my blog. I’m using the Twenty Ten theme in WordPress and then I created a child theme because I didn’t want to touch the files deep within WP.

    So what I was going was inserting all of my styles, etc into the comments.php file within my child theme root directory.

    The problem I’m experiencing is that when I fill out the form to comment on a post, it will submit, but then just scrolls back up to the top of the page…no awaiting comment moderation message at all. The URL seems to reflect the different number of comments because it changes number. But when I look inside my WordPress admin, there is no Comment awaiting moderation, either. So they just aren’t working at this point.

    Here’s the code:

    <?php function row_colors($i){
    if($i % 2) {
    echo ' class="alt"';
    } else {
    echo '';
    }
    }
    ?>
    
    <?php if(!empty($_SERVER['SCRIPT_FILENAME']) && 'comments.php' == basename($_SERVER['SCRIPT_FILENAME'])) : ?>
        <?php die('You can not access this page directly!'); ?>
    <?php endif; ?>
    
    <?php if(!empty($post->post_password)) : ?>
        <?php if($_COOKIE['wp-postpass_' . COOKIEHASH] != $post->post_password) : ?>
        <?php endif; ?>
    <?php endif; ?>
    
            <?php if($comments) : ?>  
    
            <h3>Comments</h3>
            <ol style="width:675px">
            <?php foreach($comments as $comment) : ?>
                <?php $i++; ?>
    			<li<?php row_colors($i); ?> id="comment-<?php comment_ID(); ?>" style="list-style:none; background:none">
                    <?php if ($comment->comment_approved == '0') : ?>
    			<em><?php _e('Your comment is awaiting moderation.') ?></em>
    			<br />
    			<?php endif; ?>
                    <?php comment_text(); ?>
                    <p><em><?php comment_type(); ?> by <?php comment_author_link(); ?> on <?php comment_date(); ?> at <?php comment_time(); ?></em></p>
                </li>
            <?php endforeach; ?>
            </ol>
        <?php else : ?>
            <!--<p>No comments yet</p>  -->
        <?php endif; ?>  
    
    <?php if(comments_open()) : ?>
        <?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 : ?>
     <h3>Leave a Comment</h3>
    <div class="comment-notes" style="padding:0 0 0 20px">Required fields are marked as <span style="color:#bf0808; font-size:11px">*</span>. Your email address will not be published.</div>
    
      <div class="form discussion-form" style="margin:20px 0 25px 20px">
      <div class="fieldswrap">
       <div id="initial-options" class="fields">
    
            <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 get_option('siteurl'); ?>/wp-login.php?action=logout" title="Log out of this account">Log out &raquo;</a></p>
                <?php else : ?> 
    
                    <dl class="form">
                    	<dt><label class="long" for="author">Name <?php if($req) echo "<span style='color:#bf0808; font-size:11px'>*</span>"; ?></label></dt>
                    	<dd><input id="author" name="author" type="textfield text" class="textfield long" value="<?php echo $comment_author; ?>" size="30" tabindex="1" /></dd>
                    </dl>  
    
                    <dl class="form">
                    	<dt><label class="long" for="email">Email <?php if($req) echo "<span style='color:#bf0808; font-size:11px'>*</span>"; ?></label></dt>
                        <dd><input id="email" name="email" type="text" class="textfield long" value="<?php echo $comment_author_email; ?>" size="30" tabindex="2" /></dd>
                    </dl>
    
                    <dl class="form">
                    	<dt><label class="long" for="url">Website</label></dt>
                        <dd><input id="url" name="url" type="text" class="textfield long" value="<?php echo $comment_author_url; ?>" size="30" tabindex="3" /></dd>
                    </dl>
    
                <?php endif; ?>  
    
                <dl class="form">
        			<dt><label class="long" for="comment">Comment</label> <span style="color:#bf0808; font-size:11px">*</span></dt>
                    <dd><textarea name="comment" id="comment" cols="45" rows="8" tabindex="4"></textarea></dd>
                </dl>
    
                <div class="form-actions">
    				<div style="float:right">
                    	<input name="submit" type="submit" tabindex="5" value="Submit Comment" class="button black" style="font-size:14px!important">
                <input type="hidden" name="comment_post_ID" value="<?php echo $id; ?>" />
                <?php do_action('comment_form', $post->ID); ?>
                	</div>
                </div>
            </form> 
    
        </div>
       </div>
      </div> 
    
        <?php endif; ?>
    <?php else : ?>
        <p>The comments are closed.</p>
    <?php endif; ?>

    Can you please direct me as to what I’m missing in the code, or why it’s not submitting correctly?

    Note – I followed the tutorial seen here: http://net.tutsplus.com/tutorials/wordpress/unraveling-the-secrets-of-wordpress-commentsphp-file/comment-page-5/#comments

  • The topic ‘Comments not working in Child Theme (comments.php)’ is closed to new replies.