Support » Fixing WordPress » I want to add a "Comments are closed" message

  • Resolved shilojean


    Hi all,
    I had a friend build me a custom theme and all is great except when posts reach the 30-day commenting limit I enabled using WordPress discussion settings, I’ve found that there is no message indicating that the post is closed for comments. This has caused some confusion with readers feeling like they can’t figure out how to comment, when really, the comments are simply closed.
    An example:

    awkward, right?

    Unfortunately, my developer friend is not available to help me sort this out for quite a while, and I’d like to learn how to deal with this stuff myself anyway.

    I read through the archives here, and although most of the “comment closed” posts are in regards to removing the message, I found two that involve adding the message. Alas, after reading them thoroughly and even giving it a stab at cut-and-pasting some suggested code, I’ve had no luck getting it to actually work.

    When I look at the php for my comments file, I don’t see anywhere that even deals with the concept of the comments being closed.
    Here’s my comment code, any suggestions would be deeply appreciated.

    <?php // Do not delete these lines
    	if (isset($_SERVER['SCRIPT_FILENAME']) && '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('Enter your password to view comments.'); ?></p>
    	/* This variable is for alternating comment background */
    	$oddcomment = 'class="alt" ';
    <!-- You can start editing here. -->
    <div class="allcomments">
    	<?php if ($comments) : ?>
    	<?php comments_number(__('No Comments'), __('1 Comment'), __('% Comments')); ?>
    	<?php foreach ($comments as $comment) : ?>
    		<div class="commentbox" id="comment-<?php comment_ID() ?>">
    			<?php if ($comment->comment_approved == '0') : ?>
    				<em>Your comment will be published once I confirm you're not a spambot.</em>
    		    <?php endif; ?>
    			<div class="commentmeta">
                	<strong><?php comment_author_link() ?></strong><br />
                	<small><?php comment_date() ?></small>
    			<div class="commenttext">
                	<?php comment_text() ?>
    	<?php endforeach; ?>
    	<?php else : ?>
    		<?php if ('open' == $post->comment_status) : ?>
    			<p><?php _e('Nope, no comments yet.'); ?></p>
    		<?php endif; ?>
    	<?php endif; ?>
    	<?php if ('open' == $post->comment_status) : ?>
    		<?php if ( get_option('comment_registration') && !$user_ID ) : ?>
    			<h3><?php printf(__('You must be <a href="%s">logged in</a> to post a comment.'), get_option('siteurl')."/wp-login.php?redirect_to=".urlencode(get_permalink()));?></h3>
    		<?php else : ?>
    		<div id="commentform">
    			<form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post">
    				<?php if ( $user_ID ) : ?>
    				<?php else : ?>
    					<label for="author">Name <?php if ($req) _e('<strong>required</strong>'); ?></label><br/>
    					<input type="text" name="author" id="name" class="text" value="<?php echo $comment_author; ?>" size="22" tabindex="1" /><br/>
    					<label for="email">Mail (will not be published) <?php if ($req) _e('<strong>required</strong>'); ?></label><br/>
    					<input type="text" name="email" id="email" class="text" value="<?php echo $comment_author_email; ?>" size="22" tabindex="2" /><br/>
    					<label for="url">URL</label><br/>
    					<input type="text" name="url" id="website" class="text" value="<?php echo $comment_author_url; ?>" size="22" tabindex="3" /><br/>
    				<?php endif; ?>
    				<br/><label for="message">You can leave a comment if you're into that kind of thing. No pressure.</label><br/><br/>
    				<textarea name="comment" id="message" tabindex="4" rows="9" cols="10"></textarea>
    				<input name="submit" type="submit" class="submit" tabindex="5" value="<?php echo attribute_escape(__('Submit Comment')); ?>" />
    				<input type="hidden" name="comment_post_ID" value="<?php echo $id; ?>" />
    				<?php do_action('comment_form', $post->ID); ?>
    <?php endif; ?>
    	<?php endif; ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • After many hours of syntax errors, I figured it out so I’m closing this post.
    But just in case anyone else is trying to figure this out, what I did was as follows:

    First, I removed `<?php if (‘open’ == $post->comment_status) : ?>
    <p><?php _e(‘Nope, no comments yet.’); ?></p>` from the comment code shown in my initial post.

    Then I stole this similar, but slightly different bit from a different theme that displayed the comments closed message I was after:
    `<?php if (‘open’ == $post->comment_status) : ?>
    <p class=”center”>Nope, no comments yet.</p>
    <?php else : // Comments are closed ?>
    <p><?php _e(‘Comments are closed on this post.’); ?></p>

    I stuck that bit of code in just after <div class="allcomments"> and viola! the notice appears on closed posts.

    I was wrong. While this method does get a comments closed notification message to appear, it also makes comments already left invisible. So, scratch that!

    I found the real solution and posted it in this other forum thread:

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘I want to add a "Comments are closed" message’ is closed to new replies.