Wordpress Woes - Comments not Working Properly

Discussion in 'HTML & Website Design' started by grimsqueaker, Mar 29, 2008.

  1. #1
    Please take a look here: http://one-moment.org/

    See the comments link at the end of each post? Although it's displaying alright, when you click on it, you can't enter comments in.

    This caught me by surprise today because I remember when I first started this site that the comments field worked perfectly - but no longer for some reason. Does anyone know how I might fix this?

    Thanks!
     
    grimsqueaker, Mar 29, 2008 IP
  2. Dan Schulz

    Dan Schulz Peon

    Messages:
    6,032
    Likes Received:
    436
    Best Answers:
    0
    Trophy Points:
    0
    #2
    There's no comment box in the HTML source code - meaning you've probably messed something up inside The Loop. What does your WordPress Theme code for your comments.php file look like?
     
    Dan Schulz, Mar 29, 2008 IP
  3. grimsqueaker

    grimsqueaker Peon

    Messages:
    551
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #3
    It looks like this:

    <?php if ( !empty($post->post_password) && $_COOKIE['wp-postpass_' . COOKIEHASH] != $post->post_password) : ?>
    <p><?php _e('Enter your password to view comments.'); ?></p>
    <?php return; endif; ?>
    
    <h2 id="comments"><?php comments_number(__('No Comments'), __('1 Comment'), __('% Comments')); ?> 
    <?php if ( comments_open() ) : ?>
    	<a href="#postcomment" title="<?php _e("Leave a comment"); ?>">&raquo;</a>
    <?php endif; ?>
    </h2>
    
    <?php if ( $comments ) : ?>
    <ol id="commentlist">
    
    <?php foreach ($comments as $comment) : ?>
    	<li id="comment-<?php comment_ID() ?>">
    	<?php comment_text() ?>
    	<p><cite><?php comment_type(__('Comment'), __('Trackback'), __('Pingback')); ?> <?php _e('by'); ?> <?php comment_author_link() ?> &#8212; <?php comment_date() ?> @ <a href="#comment-<?php comment_ID() ?>"><?php comment_time() ?></a></cite> <?php edit_comment_link(__("Edit This"), ' |'); ?></p>
    	</li>
    
    <?php endforeach; ?>
    
    </ol>
    
    <?php else : // If there are no comments yet ?>
    	<p><?php _e('No comments yet.'); ?></p>
    <?php endif; ?>
    
    <p><?php comments_rss_link(__('<abbr title="Really Simple Syndication">RSS</abbr> feed for comments on this post.')); ?> 
    <?php if ( pings_open() ) : ?>
    	<a href="<?php trackback_url() ?>" rel="trackback"><?php _e('TrackBack <abbr title="Uniform Resource Identifier">URI</abbr>'); ?></a>
    <?php endif; ?>
    </p>
    
    <?php if ( comments_open() ) : ?>
    <h2 id="postcomment"><?php _e('Leave a comment'); ?></h2>
    
    <?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 the_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 get_option('siteurl'); ?>/wp-login.php?action=logout" title="<?php _e('Log out of this account') ?>">Logout &raquo;</a></p>
    
    <?php else : ?>
    
    <p><input type="text" name="author" id="author" value="<?php echo $comment_author; ?>" size="22" tabindex="1" />
    <label for="author"><small>Name <?php if ($req) _e('(required)'); ?></small></label></p>
    
    <p><input type="text" name="email" id="email" value="<?php echo $comment_author_email; ?>" size="22" tabindex="2" />
    <label for="email"><small>Mail (will not be published) <?php if ($req) _e('(required)'); ?></small></label></p>
    
    <p><input type="text" name="url" id="url" value="<?php echo $comment_author_url; ?>" size="22" tabindex="3" />
    <label for="url"><small>Website</small></label></p>
    
    <?php endif; ?>
    
    <!--<p><small><strong>XHTML:</strong> You can use these tags: <?php echo allowed_tags(); ?></small></p>-->
    
    <p><textarea name="comment" id="comment" cols="100%" rows="10" tabindex="4"></textarea></p>
    
    <p><input name="submit" type="submit" id="submit" tabindex="5" value="Submit Comment" />
    <input type="hidden" name="comment_post_ID" value="<?php echo $id; ?>" />
    </p>
    <?php do_action('comment_form', $post->ID); ?>
    
    </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; ?>
    
    PHP:
    Thanks so much for your help - usually I can figure out how to get things working through trial and error, but I'm completely lost on this php stuff. :S
     
    grimsqueaker, Mar 29, 2008 IP
  4. Dan Schulz

    Dan Schulz Peon

    Messages:
    6,032
    Likes Received:
    436
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Try this one out. Make sure you copy your current comments.php file before replacing it with this one. Also bear in mind that I'm not at home right now so I can't offer any customization support (using my brother's PC right now) at this time. This version also has author comments and the separation of trackbacks from comments enabled by default (both of which can be styled with CSS).

    
    <?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"><?php _e("This page is password protected. Please enter your password to view the comments on the page."); ?></p>
    				
    				<?php
    				return;
                }
            }
    
    		/* This variable is for alternating comment background */
    		$oddcomment = 'alt';
    ?>
    <?php // You can start editing here. ?>
    <?php if ($comments) : ?>
    	    	<h2 id="comments"><?php comments_number('No Responses', 'One Response', '% Responses' );?> to &#8220;<?php the_title(); ?>&#8221;</h2> 
    	    	<ol>
    				<?php foreach ($comments as $comment) : ?>
    					<?php // Michael Martin's comment/trackback separation script ?>
    					<?php $comment_type = get_comment_type(); ?>
    					<?php if($comment_type == 'comment') { ?>
    
    	    		<li class="<?php if($comment->user_id == '1') echo 'author-comment'; else echo $oddcomment; ?>" id="comment-<?php comment_ID(); ?>">
    					<cite><?php comment_author_link(); ?> &nbsp;Says:</cite>
    					<?php if ($comment->comment_approved == '0') : ?>
    					<em>Your comment is awaiting moderation.</em>
    					<?php endif; ?>
    					<br />
    					<span class="commentmetadata">Posted on <a href="#comment-<?php comment_ID() ?>"><?php comment_date('F jS, Y') ?> at <?php comment_time() ?></a> <?php edit_comment_link('e','',''); ?></span>
    					<?php comment_text() ?>
    	    		</li>
    				<?php /* Changes every other comment to a different class */	
    					if ('alt' == $oddcomment) $oddcomment = '';
    					else $oddcomment = 'alt';
    				?>
    				<?php } else { $trackback = true; } /* End of is_comment statement */ ?>
    				<?php endforeach; /* end for each comment */ ?>
    			</ol>
    			<?php if ($trackback == true) { ?>
    			<h2 id="trackbacks">Trackbacks</h2>
    			<ol>
    			<?php foreach ($comments as $comment) : ?>
    			<?php $comment_type = get_comment_type(); ?>
    			<?php if($comment_type != 'comment') { ?>
    				<li><?php comment_author_link() ?></li>
    			<?php } ?>
    			<?php endforeach; ?>
    			</ol>
    			<?php } ?>
    			<?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) : ?>
    			<a id="respond"></a>
    			<h2>Leave a Response</h2>
    			<?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 the_permalink(); ?>#response">logged in</a> to post a comment.
    			</p>
    			<?php else : ?>
    			<form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" id="comments-form" method="post">
    				<?php if ( $user_ID ) : ?>
    				<p>
    					<strong>Hey, <a href="<?php echo get_option('siteurl'); ?>/wp-admin/profile.php"><?php echo $user_identity; ?></a></strong>! <span>(Not you? &raquo; <a href="<?php echo get_option('siteurl'); ?>/wp-login.php?action=logout" title="<?php _e('Log out of this account') ?>">Logout &raquo;</a></span>)
    				</p>
    				<p>
    					Welcome back, post your comment below.
    				</p>
    				<?php else : ?>
    				<div class="fieldset">
    					<fieldset>
    						<legend><span>Contact Information</span></legend>
    						<label for="author">Your Name</label> <input type="text" id="author" name="author" value="<?php echo $comment_author; ?>" tabindex="1" size="40" /><br />
    						<label for="email">Email: <?php if ($req) _e('(required)'); ?></label> <input type="text" id="email" name="email" value="<?php echo $comment_author_email; ?>" tabindex="2" size="40" /><br />
    						<label for="url">Website: (optional)</label> <input type="text" id="url" name="url" value="<?php echo $comment_author_url; ?>" tabindex="3" size="40" />
    					</fieldset>
    				</div>
    				<?php endif; ?>
    				<div>
    					<label for="comment">Comment:</label><br />
    					<textarea name="comment" id="comment" cols="50" rows="10" tabindex="4"></textarea><br />
    					<?php // a plugin is needed to make this work - oh and the subscribe checkbox has been commented out via PHP so it won't even be generated.  Escape from the PHP script by moving the closing delimiter to the end of this comment, then install and activate the Subscribe to Comments plugin to make this work <label for="subscribe"><input type="checkbox" id="subscribe" name="subscribe" value="subscribe" tabindex="5" />Subscribe to Comments (Email field must be filled in)</label> ?>
    				</div>
    				<div>	
    					<input name="submit" type="submit" id="submit" tabindex="6" value="Submit" />
    					<input type="hidden" name="comment_post_ID" value="<?php echo $id; ?>" />
    					<?php do_action('comment_form', $post->ID); ?>
    				</div>
    			</form>
    
    <?php endif; // If registration required and not logged in ?>
    
    <?php endif; // if you delete this the sky will fall on your head ?>
    
    PHP:
     
    Dan Schulz, Mar 29, 2008 IP
  5. grimsqueaker

    grimsqueaker Peon

    Messages:
    551
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Hey Dan - sweet thank you very much! My internet wasn't working yesterday (having someone over to repair it) and I'm typing from a public computer, but I will try that out once I can access my files again and let you know how it goes.
     
    grimsqueaker, Mar 31, 2008 IP
  6. Dan Schulz

    Dan Schulz Peon

    Messages:
    6,032
    Likes Received:
    436
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Ok, if that doesn't do it, then look in your single.php file for this line:

    <?php comments_template(); ?>
    PHP:
    If it's not there, let me know and I'll show you where to add it.
     
    Dan Schulz, Mar 31, 2008 IP
  7. od3n

    od3n Active Member

    Messages:
    715
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    60
    #7
    pm me. i can offer you online tutorial.
     
    od3n, Apr 1, 2008 IP
  8. Dan Schulz

    Dan Schulz Peon

    Messages:
    6,032
    Likes Received:
    436
    Best Answers:
    0
    Trophy Points:
    0
    #8
    I don't think he needs a tutorial - he needs a solution to his problem. I've already offered him not one but two possible solutions (all without having to see his Theme files).
     
    Dan Schulz, Apr 1, 2008 IP
  9. grimsqueaker

    grimsqueaker Peon

    Messages:
    551
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Hey Dan! Just tried it out - the first one doesn't seem like it's working, and I don't see a single.php file in my theme, but I see what you're getting at and I'll take a look around for something that looks like it codes for a single post. I'll let you know how it pans out and thank you once again for your help! :)

    ps. although I do have a comments-popup.php file, any idea what that is?

    pps:
    Here's my index.php file - it looks like the comments line has already been added, so I have no idea why it's not showing up:

    <?php 
    get_header();
    ?>
    
    	<div id="container">
    		<div id="sidebar">
    			<div class="t"><div class="tl"><div class="tr"></div></div></div>
    			<div class="m"><div class="ml"><div class="mr">
    			&nbsp;<?php get_sidebar(); ?>&nbsp;
    			</div></div></div>
    			<div class="b"><div class="bl"><div class="br"></div></div></div>
    		</div>
    
    
    		<div id="content">
    
    <?php if ( is_home() ) { ?>
    
    <center><a href="http://one-moment.org/about/"><img src="http://one-moment.org/wp-content/themes/default/images/intro.gif" border="0"></a></center>
    
    <hr>
    
    <?php } ?>
    
    			<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
    
    <?php if ( is_home() ) { ?>
    			<?php the_date('','<h2>','</h2>'); ?>
    <?php } ?>
    			<div class="post" id="post-<?php the_ID(); ?>"> 
    				<h3 class="storytitle"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h3>
    				
    <?php if ( is_home() ) { ?>
    <div class="meta"><?php _e("Filed under:"); ?> <?php the_category(',') ?> &#8212; <?php the_author() ?> @ <?php the_time() ?> <?php edit_post_link(__('Edit This')); ?></div>
    <?php } ?>
    				<div class="storycontent">
    					<?php the_content(__('(more...)')); ?>
    				</div>
    
    				<small><?php comments_popup_link(__('0 Comments'), __('1 Comment'), __('% Comments')); ?></small>
    	
    				<div class="feedback">
    			            <?php wp_link_pages(); ?>			            
    				</div>
    
    			</div>
    <?php if ( is_home() ) { ?>
    
    			<?php comments_template(); // Get wp-comments.php template ?>
    <?php } ?>
    		
    
    			<?php endwhile; else: ?>
    			<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    			<?php endif; ?>
    	
    			<div class="pagenavigation">
    				<?php posts_nav_link(' &#8212; ', __('&laquo; Previous Page'), __('Next Page &raquo;')); ?>
    			</div>
    
    		</div>
    		<div class="clear"></div>
    	</div>
    
    <?php get_footer(); ?>
    PHP:
     
    grimsqueaker, Apr 1, 2008 IP
  10. Dan Schulz

    Dan Schulz Peon

    Messages:
    6,032
    Likes Received:
    436
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Your single.php file should look something like this. Bear in mind though that mine's different than the default (or the one used by most other blogs), so you may have to adjust it to match your overall theme.

    
    <?php get_header(); ?>
    
    	<div id="content">
    		<div class="wrapper">
    		<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    			<h1><?php the_title(); ?></h1>
    			<p class="post-date"><em>Posted on <?php the_time('F jS, Y') ?> by <?php the_author() ?></em></p>
    			<?php the_content('<p>Read the rest of this entry &raquo;</p>'); ?>
    			<?php link_pages('<p><strong>Pages:</strong> ', '</p>', 'number'); ?>
    			<div class="metadata">
    				<p>
    					Posted in&#58; <?php the_category(', ') ?> <!-- | --> <?php comments_popup_link('No Comments &#187;', '1 Comment &#187;', '% Comments &#187;'); ?> <?php edit_post_link('Edit',' | 	',' '); ?>
    				</p>	   
    				<!--
    					<?php trackback_rdf(); ?>
    
    				--> 
    			</div>
    			<ul id="previous-next">
    				<li><?php previous_posts_link('','','&laquo; Previous Entries') ?></li>
    				<li><?php next_posts_link('','Next Entries &raquo;','') ?></li>
    			</ul>
    		<?php comments_template(); ?>
    		<?php endwhile; else: ?>
    		
    		<?php include (TEMPLATEPATH . '/404.php'); ?>     
    	    	
    	    	<?php endif; ?>
    		</div>
    	</div>
    
    <?php get_sidebar(); ?>
    
    <?php get_footer(); ?>
    
    PHP:
     
    Dan Schulz, Apr 1, 2008 IP
  11. grimsqueaker

    grimsqueaker Peon

    Messages:
    551
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #11
    I think I got it working! Had to add in another <?php comments_template(); ?> to the index file (not sure why but it seems to work). Thanks for pointing me in the right direction. :)
     
    grimsqueaker, Apr 1, 2008 IP