WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] WordPress "Comments Closed" Text Not Appearing (3 posts)

  1. enfotoad
    Member
    Posted 1 year ago #

    Hi there!

    I'm having trouble with getting the "Comments are closed." text to appear on a post page. The comment form goes away as desired, but the replacement text doesn't appear. Here's the code in my comments.php theme file. Any ideas?

    <div id="comments">
    	<?php if ( post_password_required() ) : ?>
    	<p>This post is password protected. Enter the password to view any comments</p>
    </div>
    
    	<?php
    			/* Stop the rest of comments.php from being processed,
    			 * but don't kill the script entirely -- we still have
    			 * to fully load the template.
    			 */
    			return;
    		endif;
    	?>
    
    	<?php if ( have_comments() ) : ?>
    
    	<h1><?php comments_number( 'No Comments Yet', '1 Comment', '% Comments' ); ?></h1>
    
    	<ol class="comments">
    		<?php wp_list_comments( array( 'callback' => 'starkers_comment' ) ); ?>
    	</ol>
    
    	<?php
    		/* If there are no comments and comments are closed, let's leave a little note, shall we?
    		 * But we don't want the note on pages or post types that do not support comments.
    		 */
    		elseif ( ! comments_open() && ! is_page() && post_type_supports( get_post_type(), 'comments' ) ) :
    	?>
    
    	<h1>Comments are closed</h1>
    
    	<?php endif; ?>
    
    	<?php comment_form(array('title_reply'=>'<h1>Share your thoughts</h1>')); ?>
    
    </div><!-- #comments -->
  2. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    the 'comments are closed' part is in the elseif part of the if ( have_comments() ) and will therefore only show if the post does not have any comments.

    change the relevant section for instance to:

    <?php if ( have_comments() ) : ?>
    
    	<h1><?php comments_number( 'No Comments Yet', '1 Comment', '% Comments' ); ?></h1>
    
    	<ol class="comments">
    		<?php wp_list_comments( array( 'callback' => 'starkers_comment' ) ); ?>
    	</ol>
    
    	<?php endif; ?>
    
    <?php /* If comments are closed, let's leave a little note, shall we?
    		 * But we don't want the note on pages or post types that do not support comments.
    		 */
    	if ( ! comments_open() && ! is_page() && post_type_supports( get_post_type(), 'comments' ) ) :
    	?>
    
    	<h1>Comments are closed</h1>
    
    	<?php endif; ?>
  3. enfotoad
    Member
    Posted 1 year ago #

    That would make a lot of sense haha! Thank you!

Topic Closed

This topic has been closed to new replies.

About this Topic