• Resolved cyber-ki

    (@cyber-ki)


    Hi I have a question and I hope someone can help me.
    I use the twenty seventeen theme and I want to edit the comments. I managed to achieve what I wanted however a small bit of the php does not feel right. I do not know php and even though it works fine now, I want to do it the proper way. This is the part I’m talking about:

    <?php
    	endif; 
    ?>

    I tried several ways but this is the only way I got it to function properly
    Is there anyone that can tell me how to write this in a prober way?
    This is the original code:

    	endif; // Check for have_comments().
    
    	// If comments are closed and there are comments, let's leave a little note, shall we?
    	if ( ! comments_open() && get_comments_number() && post_type_supports( get_post_type(), 'comments' ) ) : ?>
    
    		<p class="no-comments"><?php _e( 'Comments are closed.', 'twentyseventeen' ); ?></p>
    	<?php
    	endif;
    
    	comment_form();
    	?>
    
    </div><!-- #comments -->

    And this is the the code how it’s now (after I edited).

    	endif; // Check for have_comments().
    // If comments are closed and there are comments, let's leave a little note, shall we?
    	if ( ! comments_open() && get_comments_number() && post_type_supports( get_post_type(), 'comments' ) ) : ?>
    
    		<p class="no-comments"><?php _e( 'Comments are closed.', 'twentyseventeen' ); ?></p>
    	<?php
    	endif; 
    ?>
    		<div class="hidecform"> 
    		<input type="checkbox" id="toggle">
    		<label for="toggle" class="toggle" onclick=""></label>  
    
    <?php comment_form(); ?></div>
    
    </div><!-- #comments -->

    Thanks for taking the time to read and I really appreciate your help

Viewing 3 replies - 1 through 3 (of 3 total)
  • Your code is already quite good, there would be no problems if you left it as it is, I would expect that anyone in the future who had to read and modify this code would be able to follow it.
    This is what I would change it to if it had to exist in my perfect world:

    	endif; // Check for have_comments().
    // If comments are closed and there are comments, let's leave a little note, shall we?
    	if ( ! comments_open() && get_comments_number() && post_type_supports( get_post_type(), 'comments' ) ) {
    		echo '<p class="no-comments">' . _e( 'Comments are closed.', 'twentyseventeen' ) . '</p>';
    	}
    ?>
    	<div class="hidecform"> 
    	<input type="checkbox" id="toggle">
    	<label for="toggle" class="toggle" onclick=""></label>  
    <?php comment_form(); ?>
    	</div>
    </div><!-- #comments -->
    Thread Starter cyber-ki

    (@cyber-ki)

    Great! RossMitchell

    	<?php
    	endif; 
    ?>

    On its own ^ felt a bit empty and useless 😉

    Thanks a million!

    Not at all, it works perfectly. Just in my opinion a little verbose.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Basic PHP help needed’ is closed to new replies.