Skip to content

Instantly share code, notes, and snippets.

@ivanteoh
Created July 5, 2020 04:51
Show Gist options
  • Select an option

  • Save ivanteoh/63aca831f378360816f07a0ad3e215a1 to your computer and use it in GitHub Desktop.

Select an option

Save ivanteoh/63aca831f378360816f07a0ad3e215a1 to your computer and use it in GitHub Desktop.
WordPress Theme Development 7 - Comments
<?php
/**
* @package WordPress
* @subpackage Your_Theme
*/
?>
<!-- Comments for WP 2.7 and more -->
<?php
if (!empty($_SERVER['SCRIPT_FILENAME']) && 'comments.php' ==
basename($_SERVER['SCRIPT_FILENAME']))
die (__('Please do not load this page directly. Thanks!'));
if ( post_password_required() ) : ?>
<p><?php _e('This post is password protected. Enter the password to view
comments.'); ?></p>
<?php return; endif; // END: if ( post_password_required() ) ?>
<h3>
<?php comments_number(__('No Comments'), __('1 Comment'),
__('% Comments')); ?>
</h3>
<?php if ( have_comments() ) : // Showing all the comments ?>
<ul>
<?php wp_list_comments(); ?>
</ul>
<?php previous_comments_link(); ?>
<?php next_comments_link(); ?>
<?php else : // this is displayed if there are no comments so far ?>
<p><?php _e('No comments yet.'); ?></p>
<?php endif; // END: if ( $comments ) ?>
<?php if ( comments_open() ) : ?>
<div id="respond">
<h3><?php comment_form_title( 'Leave a Reply', 'Leave a Reply to %s' ); ?>
</h3>
<div id="cancel-comment-reply">
<small><?php cancel_comment_reply_link() ?></small>
</div>
<?php if ( get_option('comment_registration') && !$user_ID ) :
// If registration required ?>
<p><?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()));?></p>
<?php else : // If registration do not required ?>
<form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php"
method="post" id="commentform">
<?php if ( $user_ID ) : // Log in user info ?>
<p><?php printf(__('Logged in as %s.'),
'<a href="'.get_option('siteurl').'/wp-admin/profile.php">'
.$user_identity.'</a>'); ?>
<a href="<?php echo wp_logout_url(get_permalink()); ?>"
title="<?php _e('Log out of this account'); ?>">
<?php _e('Log out &raquo;'); ?></a></p>
<?php else : // Public user ?>
<p><input type="text" name="author" id="author" value="
<?php echo $comment_author; ?>" size="22" tabindex="1" />
<label for="author"><small><?php _e('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>
<?php _e('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><?php _e('Website'); ?></small></label></p>
<?php endif; ?>
<p><small><strong>XHTML:</strong>
<?php printf(__('You can use these tags: %s'), 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="<?php echo attribute_escape(__('Submit Comment')); ?>" /></p>
<?php comment_id_fields(); ?>
<?php do_action('comment_form', $post->ID); ?>
</form>
</div>
<?php endif; // END: if ( get_option('comment_registration') && !$user_ID )
// 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; // END: if ( comments_open() )?>
<?php if ( is_singular() ) wp_enqueue_script( 'comment-reply' );
// enables nested comments in WP 2.7 ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment