comments.php

Description: Displays the comments form.

This template includes the following templates:

  • N/A.

Template Code

			<div id="comments">
<?php
	$req = get_option('require_name_email'); // Checks if fields are required. Thanks, Adam. ;-)
	if ( 'comments.php' == basename($_SERVER['SCRIPT_FILENAME']) )
		die ( 'Please do not load this page directly. Thanks!' );
	if ( ! empty($post->post_password) ) :
		if ( $_COOKIE['wp-postpass_' . COOKIEHASH] != $post->post_password ) :
?>
				<div class="nopassword"><?php _e('This post is password protected. Enter the password to view any comments.', 'sandbox') ?></div>
			</div><!-- .comments -->
<?php
		return;
	endif;
endif;
?>
<?php if ( $comments ) : ?>
<?php global $sandbox_comment_alt ?>

<?php /* numbers of pings and comments */
$ping_count = $comment_count = 0;
foreach ( $comments as $comment )
	get_comment_type() == "comment" ? ++$comment_count : ++$ping_count;
?>
<?php if ( $comment_count ) : ?>
<?php $sandbox_comment_alt = 0 ?>

				<div id="comments-list" class="comments">
					<h3><?php printf($comment_count > 1 ? __('<span>%d</span> Comments', 'sandbox') : __('<span>One</span> Comment', 'sandbox'), $comment_count) ?></h3>

					<ol>
<?php foreach ($comments as $comment) : ?>
<?php if ( get_comment_type() == "comment" ) : ?>
						<li id="comment-<?php comment_ID() ?>" class="<?php sandbox_comment_class() ?>">
							<div class="comment-author vcard"><span class="fn n"><?php comment_author_link() ?></span></div>
							<div class="comment-meta"><?php printf(__('Posted %1$s at %2$s <span class="meta-sep">|</span> <a href="%3$s" title="Permalink to this comment">Permalink</a>', 'sandbox'),
										get_comment_date(),
										get_comment_time(),
										'#comment-' . get_comment_ID() );
										edit_comment_link(__('Edit', 'sandbox'), ' <span class="meta-sep">|</span> <span class="edit-link">', '</span>'); ?></div>
<?php if ($comment->comment_approved == '0') _e("\t\t\t\t\t<span class='unapproved'>Your comment is awaiting moderation.</span>\n", 'sandbox') ?>
							<?php comment_text() ?>
						</li>
<?php endif; /* if ( get_comment_type() == "comment" ) */ ?>
<?php endforeach; ?>

					</ol>
				</div><!-- #comments-list .comments -->

<?php endif; /* if ( $comment_count ) */ ?>
<?php if ( $ping_count ) : ?>
<?php $sandbox_comment_alt = 0 ?>

				<div id="trackbacks-list" class="comments">
					<h3><?php printf($ping_count > 1 ? __('<span>%d</span> Trackbacks', 'sandbox') : __('<span>One</span> Trackback', 'sandbox'), $ping_count) ?></h3>

					<ol>
<?php foreach ( $comments as $comment ) : ?>
<?php if ( get_comment_type() != "comment" ) : ?>

						<li id="comment-<?php comment_ID() ?>" class="<?php sandbox_comment_class() ?>">
							<div class="comment-author"><?php printf(__('By %1$s on %2$s at %3$s', 'sandbox'),
									get_comment_author_link(),
									get_comment_date(),
									get_comment_time() );
									edit_comment_link(__('Edit', 'sandbox'), ' <span class="meta-sep">|</span> <span class="edit-link">', '</span>'); ?></div>
<?php if ($comment->comment_approved == '0') _e('\t\t\t\t\t<span class="unapproved">Your trackback is awaiting moderation.</span>\n', 'sandbox') ?>
							<?php comment_text() ?>
						</li>
<?php endif /* if ( get_comment_type() != "comment" ) */ ?>
<?php endforeach; ?>

					</ol>
				</div><!-- #trackbacks-list .comments -->

<?php endif /* if ( $ping_count ) */ ?>
<?php endif /* if ( $comments ) */ ?>
<?php if ( 'open' == $post->comment_status ) : ?>
				<div id="respond">
					<h3><?php _e('Post a Comment', 'sandbox') ?></h3>

<?php if ( get_option('comment_registration') && !$user_ID ) : ?>
					<p id="login-req"><?php printf(__('You must be <a href="%s" title="Log in">logged in</a> to post a comment.', 'sandbox'),
					get_option('siteurl') . '/wp-login.php?redirect_to=' . get_permalink() ) ?></p>

<?php else : ?>
					<div class="formcontainer">	
						<form id="commentform" action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post">

<?php if ( $user_ID ) : ?>
							<p id="login"><?php printf(__('<span class="loggedin">Logged in as <a href="%1$s" title="Logged in as %2$s">%2$s</a>.</span> <span class="logout"><a href="%3$s" title="Log out of this account">Log out?</a></span>', 'sandbox'),
								get_option('siteurl') . '/wp-admin/profile.php',
								wp_specialchars($user_identity, true),
								get_option('siteurl') . '/wp-login.php?action=logout&redirect_to=' . get_permalink() ) ?></p>

<?php else : ?>

							<p id="comment-notes"><?php _e('Your email is <em>never</em> published nor shared.', 'sandbox') ?> <?php if ($req) _e('Required fields are marked <span class="required">*</span>', 'sandbox') ?></p>

							<div class="form-label"><label for="author"><?php _e('Name', 'sandbox') ?></label> <?php if ($req) _e('<span class="required">*</span>', 'sandbox') ?></div>
							<div class="form-input"><input id="author" name="author" type="text" value="<?php echo $comment_author ?>" size="30" maxlength="20" tabindex="3" /></div>

							<div class="form-label"><label for="email"><?php _e('Email', 'sandbox') ?></label> <?php if ($req) _e('<span class="required">*</span>', 'sandbox') ?></div>
							<div class="form-input"><input id="email" name="email" type="text" value="<?php echo $comment_author_email ?>" size="30" maxlength="50" tabindex="4" /></div>

							<div class="form-label"><label for="url"><?php _e('Website', 'sandbox') ?></label></div>
							<div class="form-input"><input id="url" name="url" type="text" value="<?php echo $comment_author_url ?>" size="30" maxlength="50" tabindex="5" /></div>

<?php endif /* if ( $user_ID ) */ ?>

							<div class="form-label"><label for="comment"><?php _e('Comment', 'sandbox') ?></label></div>
							<div class="form-textarea"><textarea id="comment" name="comment" cols="45" rows="8" tabindex="6"></textarea></div>

							<div class="form-submit"><input id="submit" name="submit" type="submit" value="<?php _e('Post Comment', 'sandbox') ?>" tabindex="7" /><input type="hidden" name="comment_post_ID" value="<?php echo $id; ?>" /></div>

							<?php do_action('comment_form', $post->ID); ?>

						</form><!-- #commentform -->
					</div><!-- .formcontainer -->
<?php endif /* if ( get_option('comment_registration') && !$user_ID ) */ ?>

				</div><!-- #respond -->
<?php endif /* if ( 'open' == $post->comment_status ) */ ?>

			</div><!-- #comments -->

This template includes the following tags:

  • __() is a WordPress function used to mark a string for translation to another language. It is similar to _e(), except that __() returns the string while _e() echoes it.
  • _e() is a WordPress function used to mark a string for translation to another language. It is similar to __(), except that __() returns the string while _e() echoes it.
  • bloginfo() is a WordPress function that displays information about your blog. Using various parameters, the function can display the following strings:
    • Blog title;
    • Blog tagline;
    • Administrator's email address;
    • Document content-type;
    • Document charset;
    • WordPress version;
    • Blog URL;
    • Pingback URL;
    • URL of the RSS 0.92, RSS 1.0, RSS 2.0, or Atom feed;
    • URL of the comments feed;
    • URL of the directory in which WordPress is installed;
    • URL of the current template's directory;
    • URL of the current style.css file;
    • URL of the stylesheet directory (deprecated)
  • basename() is a PHP filename function which returns the filename component of a path.
  • comment_author_link() is a WordPress tag which displays the comment author's name. This tag must be used within The Loop, or within a comment loop.
  • comment_ID() is a WordPress tag which displays the ID of a comment. This tag must be used within The Loop, or within a comment loop.
  • comment_text() is a WordPress tag which displays the text of a comment. This tag must be used within The Loop, or within a comment loop.
  • do_action() is a WordPress function which creates a hook for attaching actions via add_action.
  • edit_comment_link() is a WordPress function which displays a link to edit the current comment, provided that the user is logged in and has the appropriate permissions. This tag must be used within The Loop, or within a comment loop.
  • get_comment_author_link() is a WordPress hook.
  • get_comment_date() is a WordPress hook.
  • get_comment_ID() is a WordPress hook.
  • get_comment_time() is a WordPress hook.
  • get_comment_type() is a WordPress hook.
  • get_option() is a WordPress tag used to get a named option from the options database table. See the Option Reference for a list of valid parameters.
  • get_permalink() is a WordPress function which returns, but does not display, the permalink to a post. It can be used anywhere in a WordPress template.
  • printf() is a PHP string function used to output a formatted string.
  • sandbox_comment_class() is a Sandbox-specific function defined in the functions.php file. It adds semantic classes to the li element of each comment, trackback, and pingback.
  • wp_specialchars() is a WordPress function that is "like the PHP function htmlspecialchars except it doesn't double-encode HTML entities." (Function Reference)

HTML Skeleton

<div id="comments">

	<div id="comments-list" class="comments">
		<h3><span>[#]</span> Comments</h3>
		<ol>
			<li id="comment-[#]" class="comment c0 c-y[YEAR] c-m[MONTH] c-d[DAY] c-h[HOUR] alt">
				<div class="comment-author vcard">
					<span class="fn n">[USER]</span>
				</div>
				<div class="comment-meta">
					Posted [MONTH DAY, YEAR] at [TIME]
					<span class="meta-sep">|</span>
					<a href="#comment-[#]" title="Permalink to this comment">Permalink</a>
					<span class="meta-sep">|</span>
					<span class="edit-link">[EDIT LINK]</span>
				</div>
				<p>[COMMENT CONTENT]</p>
			</li>
		</ol>
	</div>
	<!-- #comments-list .comments -->

	<div id="respond">
		<h3>Post a Comment</h3>

		<div class="formcontainer">
			<form id="commentform">
				<p id="login"><span class="loggedin">Logged in as [USERNAME].</span>
				<span class="logout">Log out?</span></p>
				<div class="form-label">
					<label for="comment">Comment</label>
				</div>
				<div class="form-textarea">
					<textarea id="comment"></textarea>
				</div>
				<div class="form-submit">
					<input id="submit" />
					<input />
				</div>
				<input />
			</form>
			<!-- #commentform -->

		</div>
		<!-- .formcontainer -->

	</div>
	<!-- #respond -->

</div>
<!-- #comments -->

Related CSS Styles

Resources

  • N/A