Unraveling the Secrets of WordPress’ Comments.php File

May 29th in Wordpress by Gilles Maes
WordPress seems to be everywhere these days, and it's no wonder with it's ease of use and ease of customization. In this tutorial, I'll be dissecting the default WordPress theme's comments.php structure and giving you various snippets of code to make your skinning easier.
PG

Author: Gilles Maes

Gilles Maes is a Belgian webdeveloper with a particular passion for everything that is related to WordPress. Aside from front-end development with xHTML, CSS and Javascript he also fools around in PHP.

For your reference, I've also included a small table of contents.
  1. The PHP backend
  2. General code
    1. Preventing direct access to comments.php
    2. Is a password required?
  3. Displaying the comments
    1. Basic comment template tags
    2. The final result
  4. The comment form
    1. Conditional statement overview
    2. Inserting the form
  5. Some little tricks
    1. Gravatars
    2. Comment numbers
    3. Comment links
    4. Editing comments
    5. Alternating colors for comments
    6. Displaying the allowed tags
    7. Comments RSS link
  6. Conclusion

1. The PHP Backend

<?php if(!empty($_SERVER['SCRIPT_FILENAME']) && 'comments.php' == basename($_SERVER['SCRIPT_FILENAME'])) : ?>
<?php endif; ?>
	
<?php if(!empty($post->post_password)) : ?>
	<?php if($_COOKIE['wp-postpass_' . COOKIEHASH] != $post->post_password) : ?>
	<?php endif; ?>
<?php endif; ?>

<?php if($comments) : ?>
	<?php foreach($comments as $comment) : ?>
		<?php if ($comment->comment_approved == '0') : ?>
		<?php endif; ?>
	<?php endforeach; ?>
<?php else : ?>
<?php endif; ?>

<?php if(comments_open()) : ?>
	<?php if(get_option('comment_registration') && !$user_ID) : ?>
	<?php else : ?>
		<?php if($user_ID) : ?>
		<?php else : ?>
		<?php endif; ?>
	<?php endif; ?>
<?php else : ?>
<?php endif; ?>

This is the raw PHP code that makes your comments.php file function. To a novice, this might look intimidating. However, do not worry: with this tutorial everything in your comments file will become crystal clear!

2. General Code

Preventing direct access to comments.php

<?php if(!empty($_SERVER['SCRIPT_FILENAME']) && 'comments.php' == basename($_SERVER['SCRIPT_FILENAME'])) : ?>
<?php endif; ?>

This line of code prevents users from viewing comments.php by accident. This page is meant to be included in a post page, not separately. You could consider this a security measure. Inside the statement, you could insert any message you'd want to be displayed to the person viewing the comments.php file, preferably a die statement.

<?php if(!empty($_SERVER['SCRIPT_FILENAME']) && 'comments.php' == basename($_SERVER['SCRIPT_FILENAME'])) : ?>
	<?php die('You can not access this page directly!'); ?>
<?php endif; ?>

Is a password required?

<?php if(!empty($post->post_password)) : ?>
	<?php if($_COOKIE['wp-postpass_' . COOKIEHASH] != $post->post_password) : ?>
	<?php endif; ?>
<?php endif; ?>

This statement (well, 2 actually, but it makes more sense if you view them as one) checks whether a password is required to view the post. Obviously, if you don't have the password to view the post, you're also not allowed to view the comments.

The first if checks whether there is a password set. The second if statement checks whether there is a cookie with a password in place and displays the according message when it's not there. You can customize the error message by placing whatever you choose inside the second if statement.

3. Displaying The Comments

<?php if($comments): ?>
  	<?php foreach ($comments as $comment) : ?>
		<?php if ($comment->comment_approved == '0') : ?>
		<?php endif; ?>
	<?php endforeach; ?>
<?php else : ?>
<?php endif; ?>

This first conditional statement (if($comments)) checks if there are comments and then loops through them with a foreach statement. Inside the foreach statement, you'll notice the following conditional statement: if($comment->comment_approved == '0'). This checks if the comment has been approved, and shows a message if it's not yet approved.

An example of this would be the following piece of code.

<?php if($comments) : ?>
	<ol>
  	<?php foreach($comments as $comment) : ?>
		<li>
			<?php if($comment->comment_approved == '0') : ?>
				<p>Your comment is awaiting approval</p>
			<?php endif; ?>
			<p>Your comment</p>
		</li>
	<?php endforeach; ?>
	</ol>
<?php else : ?>
	<p>No comments</p>
<?php endif; ?>

Basic comment template tags

To make this a functional piece of code, you'll need to use the template tags WordPress provides.

Template Tag Description
<?php comment_ID(); ?> the ID of a comment
<?php comment_author(); ?> the author of a comment
<?php comment_author_link(); ?> the author of a comment, wrapped with a link to his website if he specified one
<?php comment_type(); ?> the type of comment; pingback, trackback or a comment
<?php comment_text(); ?> the actual comment
<?php comment_date(); ?> the date it was posted
<?php comment_time(); ?> the time it was posted

The final result

<?php if($comments) : ?>
	<ol>
  	<?php foreach($comments as $comment) : ?>
		<li id="comment-<?php comment_ID(); ?>">
			<?php if ($comment->comment_approved == '0') : ?>
				<p>Your comment is awaiting approval</p>
			<?php endif; ?>
			<?php comment_text(); ?>
			<cite><?php comment_type(); ?> by <?php comment_author_link(); ?> on <?php comment_date(); ?> at <?php comment_time(); ?></cite>
		</li>
	<?php endforeach; ?>
	</ol>
<?php else : ?>
	<p>No comments yet</p>
<?php endif; ?>

Inserting this into comments.php would give you a ordered list with the comments and the required information or display a message stating that there aren't any comments.

4. The Comment Form

Are you still following me? Good! We're almost there. We just need to process that comment form... Okay, maybe I lied about almost being there. The comment form is actually one of the harder parts of the entire comments.php skin file.

You'll be bombarded with several conditional statements (is a login required, are you logged in, ...). This part is where most starting skinners have the most trouble: misplacing form elements could prevent the form from working at all, without giving a specific PHP error.

To give you an insight into the conditional statements that are involved in the comment form, I'll first be explaining those statements, and include the HTML later on explaining why it should be where it is.

Conditional statement overview

<?php if(comments_open()) : ?>
	<?php if(get_option('comment_registration') && !$user_ID) : ?>
	<?php else : ?>
		<?php if($user_ID) : ?>
		<?php else : ?>
		<?php endif; ?>
	<?php endif; ?>
<?php else : ?>
<?php endif; ?>

The first conditional statement you encounter is <?php if(comments_open()) : ?> . This basically checks if the comments are open. Obviously, if the comments are closed, you can't post a comment and the comment form is not needed. You can put the message you want to be displayed if the comments are closed between the last <?php else : ?> and <?php endif; ?>.

The second conditional statement (<?php if(get_option('comment_registration') && !$user_ID) : ?>) checks whether you need to be registred to post a comment and if you are logged in. If the conditional statement is fulfilled, the script should display a link to a place where users can log in. If registration is not required or you are already logged in, the script will continue with the else part and display the form.

Our final conditional statement then checks if you are logged in or not. Obviously, if you're already logged in it's useless to make you fill in your name, email and website again.

Inserting the form

Congratulations, we've plowed through all of the conditional statements in the comments.php file. Now, all that is left is to add the form in there.

The first thing I can hear you think is: where the hell is that form going to start? Well, you just have to follow common sense. The second conditional statement checks whether you have to be logged in or not, therefor you'd have to display no form until after this statement. Thus the entire form is located inside this conditional statement.

<?php if(comments_open()) : ?>
	<?php if(get_option('comment_registration') && !$user_ID) : ?>
		<p>You must be <a href="<?php echo get_option('siteurl'); ?>/wp-login.php?redirect_to=<?php echo urlencode(get_permalink()); ?>">logged in</a> to post a comment.</p><?php else : ?>
		<form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" id="commentform">
			<?php if($user_ID) : ?>
			<?php else : ?>
			<?php endif; ?>
		</form>
	<?php endif; ?>
<?php else : ?>
	<p>The comments are closed.</p>
<?php endif; ?>

I've also thrown in the link to the login page, just as I found it in the default comments.php. As I said before, the last conditional statement checks whether you're logged in or not. Obviously, the name, email and website input fields are only displayed if you're not logged in. Let's throw them in there!

<?php if(comments_open()) : ?>
	<?php if(get_option('comment_registration') && !$user_ID) : ?>
		<p>You must be <a href="<?php echo get_option('siteurl'); ?>/wp-login.php?redirect_to=<?php echo urlencode(get_permalink()); ?>">logged in</a> to post a comment.</p><?php else : ?>
		<form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" id="commentform">
			<?php if($user_ID) : ?>
				<p>Logged in as <a href="<?php echo get_option('siteurl'); ?>/wp-admin/profile.php"><?php echo $user_identity; ?></a>. <a href="<?php echo get_option('siteurl'); ?>/wp-login.php?action=logout" title="Log out of this account">Log out &raquo;</a></p>
			<?php else : ?>
				<p><input type="text" name="author" id="author" value="<?php echo $comment_author; ?>" size="22" tabindex="1" />
				<label for="author"><small>Name <?php if($req) echo "(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>Mail (will not be published) <?php if($req) echo "(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>Website</small></label></p>
			<?php endif; ?>
		</form>
	<?php endif; ?>
<?php else : ?>
	<p>The comments are closed.</p>
<?php endif; ?>

Alright! We're almost there! We just need to add in some simple lines of code such as a textarea and a submit button. These go after the last conditional statement, since it's irrelevant for these elements if you are logged in or not.

<?php if(comments_open()) : ?>
	<?php if(get_option('comment_registration') && !$user_ID) : ?>
		<p>You must be <a href="<?php echo get_option('siteurl'); ?>/wp-login.php?redirect_to=<?php echo urlencode(get_permalink()); ?>">logged in</a> to post a comment.</p><?php else : ?>
		<form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" id="commentform">
			<?php if($user_ID) : ?>
				<p>Logged in as <a href="<?php echo get_option('siteurl'); ?>/wp-admin/profile.php"><?php echo $user_identity; ?></a>. <a href="<?php echo get_option('siteurl'); ?>/wp-login.php?action=logout" title="Log out of this account">Log out &raquo;</a></p>
			<?php else : ?>
				<p><input type="text" name="author" id="author" value="<?php echo $comment_author; ?>" size="22" tabindex="1" />
				<label for="author"><small>Name <?php if($req) echo "(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>Mail (will not be published) <?php if($req) echo "(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>Website</small></label></p>
			<?php endif; ?>
			<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="Submit Comment" />
			<input type="hidden" name="comment_post_ID" value="<?php echo $id; ?>" /></p>
			<?php do_action('comment_form', $post->ID); ?>
		</form>
	<?php endif; ?>
<?php else : ?>
	<p>The comments are closed.</p>
<?php endif; ?>

This code should be pretty self-explanatory. A textarea field for the comment, a submit button, a hidden input field with the comments' future ID and a PHP snippet (<?php do_action('comment_form', $post->ID); ?>) WordPress requires to make the comment form function.

Voila! That's all folks! You've now got your fully ready comments.php file. View this file to get all the PHP and HTML code that is required. You should end up with this (I simply replaced the default skin's comments.php file with ours and added some minor styling to it.)

Comments preview

5. Some Little Tricks

Of course, you now only have a basic comments.php file. There's tons of things you could do to further improve it. I'll list some little tips and tricks to help you on your way.

Gravatars

As of WordPress 2.5, there is a custom WordPress template tag to embed gravatars. It pulls the gravatar from the email the visitor entered. The code to do this is very simple.

<?php echo get_avatar($author_email, $size, $default_avatar ); ?>

You can replace $author_email with the nifty get_comment_author_email(); function, $size is the height (and width) of the avatar and $default_avatar is a link to the default avatar image (displayed when the commenter has no gravatar).

Insert this code inside the foreach loop that displays the comments. The output is a image with the classes avatar and avatar-$size (where $size is the size you specified). With some minor CSS editing, you could end up with something like this:

Comment Gravatars

Comment numbers

I purposely left out headers in the comments.php file we created later, since I believed they would make for excess code in a learning process that's difficult enough as it is. Obviously, I'm not forgetting them though.

Usually, people have a heading displaying something similar to "3 comments so far". This is really easy to achieve thanks to the template tags WordPress offers.

<?php comments_number($zero_comments, $one_comment, $more_comments); ?> 

It's pretty self-explanatory: $zero_comments is the text to display when there are no comments, $one_comment when there is one comment and $more_comments when there are multiple comments. A real life example would be like this:

<?php comments_number('No comments', 'One comment', '% comments'); ?> 

I used % for multiple comments, since the comments_number function then replaces the % with the number of comments (2, 3, …)

Used in our comments.php file, you'll end up with something like this:

Comment numbers

To display a link to the comments part (with the number of comments displaying aswell), you simply use the following code.

<?php comments_popup_link($zero_comments, $one_comment, $more_comments, $css_class, $comments_closed); ?> 

The first 3 parameters in this function are the same as the above comments_number function. $css_class is, obviously, the css class that you give to the <a> tag and $comments_closed is the text that should be displayed when the comments are closed. When applying this to a theme, this is a possible way to use it.

<?php comments_popup_link('No comments', 'One comment', '% comments', 'comments-link', 'Comments are closed'); ?> 

This would then give you a link with the class comments-link

Editing comments

Sometimes you'll want to immediately edit a comment. Luckily, with the edit_comment_link function, you can easily go to the right page to edit it, instead of having to browse to your admin panel to finally reach that comment. Usage is as such:

<?php edit_comment_link($link_text, $before_link, $after_link); ?> 

You have to put this inside the foreach comment loop. Parameters are quite obvious: $link_text is the anchor text for the edit link, $before_link and $after_link respectively are the text or code to display before or after the link.

This really makes it easy to change a comment; you could simply add a small 'Edit' link to your comment meta information (only viewable by the admin). This is what it could look like:

Comment Edit Link

Alternating colors for comments

It's possible that you'd want to have alternating row colors for your comments, to make a clearer separation. Doing this is relatively easy. First, add the following code to the top of the page:

function alternate_rows($i){
if($i % 2) {
echo ' class="alt"';
} else {
echo '';
} }

Then add the following inside the foreach loop (again). You could simply replace <li id="comment-<?php comment_ID(); ?>"> with this:

<?php $i++; ?>
<li<?php alternate_rows($i); ?> id="comment-<?php comment_ID(); ?>">

This will give every other comment the class alt, thus making it possible to change their appearance through CSS.

I decided to make a function for it, to have less clutter in your actual theme file. You could add the function definition into your functions.php file if you'd like to, but it makes more sense, to me, to have it at the top of your page.

Alternating rows make it easier to distinguish different comments; once implemented you might have something like this:

alternate color comments

Displaying the allowed tags

To display the code that visitors are allowed to use in their comments, simply use this little snippet.

Allowed tags: <?php echo allowed_tags(); ?>

Then you'll simply get a list of the tags that are allowed in your comments, like this:

allowed tags

Comments RSS link

To get a link to the RSS feed for the comments of a certain post, simply insert the code below into your comments.php file on the place where you want it to be.

<?php comments_rss_link($link_text); ?>

Then simply replace $link_test with the anchor text for the RSS link.

This can come in handy if you want to give your visitors the opportunity to subscribe to the comment feed for a specific article or blog post. You could implement it like this:

comments rss link

6. Conclusion

I hope you've enjoyed this *ahem* little article about skinning your WordPress comments.php file. You can get the full code here, with the tricks I showed included in it:

  • gravatars,
  • alternate row colors,
  • edit link,
  • comments rss link.

Obviously, the comments link isn't included since this has to be used inside of the loop.

Best of luck in your WordPress skinning adventures!


Related Posts

Check out some more great tutorials and articles that you might like

Enjoy this Post?

Your vote will help us grow this site and provide even more awesomeness

Plus Members

Source Files, Bonus Tutorials and
More for $9 a month for all TUTS+
sites in one subscription.

Join Now

User Comments

( ADD YOURS )
  1. PG

    Pavel Ciorici May 29th

    Very useful artcile… I expect more articles about WordPress….

    ( Reply )
  2. PG

    Andrew Pryde May 29th

    Very Nice I develop using WordPress as a CMS so I may submit a tutorial on how to reduce it in to a CMS so that it is simple to use for the site admin.

    Andrew Pryde

    ( Reply )
  3. PG

    Erik Reagan May 29th

    This looks like a very nice overview of comments in wordpress. Perhaps you should consider a series of tuts like this one including other aspects of Wordpress. Thanks for all the hard work!

    ( Reply )
  4. PG

    Shane May 29th

    The documentation over at wordpress.com is much better than it used to be, but there is still a need for in depth tutorials like these. Since commenting is a central part of any successful blog, it’s most welcome to read an in depth analysis about how it works in wordpress.

    Thanks for writing it Gilles.

    ( Reply )
  5. PG

    Jbcarey May 29th

    This article is worth gold, not just 150$ :D

    As Shane said “Thanks for writing it Gilles.”

    ( Reply )
  6. PG

    Danny May 29th

    please write more like this but for all the other confusing files!! :)

    ( Reply )
  7. PG

    Headshot May 29th

    Awesome Tutorial!!
    I never knew how to get the avatar’s lol.

    ( Reply )
  8. PG

    freddie May 29th

    I have a great doubt with Wordpress: it’s useful only for blogs or anyone use it for other functions (like a cms) ? Anyway this post is clear and very interesting. Thanks

    ( Reply )
  9. PG

    PixlNinja May 29th

    ***** 5 Star Rating !!
    Thanks for this great article. May be some more WordPress topic specific article will be good for self learners like me. Sometimes i will write about things like this in my blog http://featherpot.com

    ( Reply )
  10. PG

    PixlNinja May 29th

    Sorry i forgot one thing…
    With some CSS and php trick designers can highlight the author/ Blog admins comments

    See the following :

    The default WordPress Comment loop is like this :


    <li class="" id="comment-">

    If you modify it like this :


    <li class="comment_author_email == "author@domain.com") echo 'author'; else echo $oddcomment; ?> item" id="comment-">

    (replace the “author@domain.com” with the authors email ID)

    The new comment loop will detect the authors comments

    And to style the authors comment to make it unique from all other comments add the HTML/PHP like this :

    and in the css file of your template add some more classes like this :

    li.author span.author_meta a {
    background: url(path/to/image.gif) no-repeat left center;
    padding-left: 20px;
    }

    Try this as your own, and see the change in authors comment from all other comments ! :)

    ( Reply )
  11. PG

    mark May 29th

    you should create a website called wordpresstuts and soley focus on wordpress, badly needed on the
    internet.

    ( Reply )
  12. PG

    Pavel Ciorici May 29th

    @mark, wptuts.com sounds better :)

    ( Reply )
  13. PG

    Tom May 29th

    Nice guide, but it lacks something: how to keep separate comments and trackbacks :)
    It’s an important customization and it increases usability a lot.

    ( Reply )
  14. PG

    Evako May 29th

    wptuts sounds like a good idea….We need more tuts on wordpress from biggener ti intermiedete level…
    Nice tut!

    ( Reply )
  15. PG

    D. Carreira May 29th

    Here is a great tutorial! It will be very usefull to me, because I’ll do a blog with WordPress in a few days.

    Thanks

    David Carreira

    ( Reply )
  16. PG

    Ben Griffiths May 29th

    I hate editing wordpress – this guide is great, makes it all nice and simple – thanks!

    ( Reply )
  17. PG

    Gilles May 29th

    Hey,

    thanks for all the positive comments so far! I’ll be looking to add in the admin highlight feature, and I was planning on adding a item to separate trackbacks, pingbacks & comments but the idea I had for it didn’t work out. I’ll see if I can add something on to this.

    As for that WordPress tutorial site :p I am actually the owner of http://www.wordpressdeveloper.com but I’m too afraid of the WordPress lawyers to use it :p

    Again, thanks for all the nice comments :D

    ( Reply )
  18. PG

    Matt Przybylski May 29th

    Very nice tutorial. I’m about to re-skin my blog and the comments on the new template I’m using as a base look terrible. I was worried about not being able to do it but how you’ve laid them out here is almost exactly how I wanted to display them so this saves me heaps of time! Thanks.

    ( Reply )
  19. PG

    J. Koning May 29th

    That’s really a great tutorial!
    I just starting on making my own WP theme. So this is just the best timing ever! :D

    Thanks for the hard work!

    ( Reply )
  20. PG

    Keith May 29th

    My first comment here. Great Article, as others have said… More Wordpress Tutorials Please

    ( Reply )
  21. PG

    Robin May 29th

    Gilles, thanks for breaking this down into an easy to read format. While the wordpress.org site has good documentation, your post really gets into the thick of it. As others have mentioned in their comments, I think you should continue on the path of these WP tutorials. One thing I can think of off the top of my head where I always run into issues is with the wp_listpages function and excluding pages and so forth, especially within loops (like making the home button link not appear on the homepage) and using this functionality with permalinks (not the &id method)

    Thanks again.

    ( Reply )
  22. PG

    Gelay May 29th

    Nice. Some more tutes on WordPress please.

    ( Reply )
  23. PG

    Razvan May 29th

    Great article Gilles, thanks!

    ( Reply )
  24. PG

    Melvin Nieves May 29th

    Love the wordpress stuff, keep it coming! Thanks Giles.

    ( Reply )
  25. PG

    web design May 29th

    The enormous commercial interest in the Web has created an enormous demand for enhanced presentations.

    ( Reply )
  26. PG

    bompa May 29th

    this is exactly why I don’t mind paying for an expressionengine copy. wp templating is a b*tch!

    ( Reply )
  27. PG

    Snorri3D May 29th

    nice article would love to see more WP tuts realated
    nice one :D

    ( Reply )
  28. PG

    Andrew May 29th

    I’m so glad to see a wordpress tutorial, I would love to see more like this in the future!

    ( Reply )
  29. PG

    Yashvin May 30th

    keep it up!

    ( Reply )
    1. PG

      Art September 20th

      Sorry for the first comment, I was just trying the “add your comment” form… Greate tuto. Thanks

      ( Reply )
  30. PG

    giackop May 30th

    It’s very useful.. Congrats.. But couldn’t you make this before??? Just kidding!!

    Thanx again..

    ( Reply )
  31. PG

    Prof Kienstra May 30th

    Great tutorial. As someone who is interested in design for a weblog and tampering with my own blog, but is also relatively clueless to PHP this is a great way to go through the comments.php site. Definitely one to keep and study often.

    Thanks for sharing! Will be back for more.

    ( Reply )
  32. PG

    Hendri May 30th

    Nice tuts Gilles Maes! more WP please :)

    ( Reply )
  33. PG

    niuhuifei May 30th

    So nice! yesterday, I have just read the comment cods two times.

    ( Reply )
  34. PG

    Christian Mejia May 30th

    I’ve been afraid to dabble in Word Press. Now I have no excuse! Thanks for this great tut.

    ( Reply )
  35. PG

    design May 30th

    That’s it. Really nice!

    ( Reply )
  36. PG

    Nico May 30th

    Very nice!

    ( Reply )
  37. PG

    Dave Keffen May 31st

    Excellent information.

    Thanks for the research, this has saved me a few hours.

    ( Reply )
  38. PG

    Qbrushes May 31st

    still fiddling with xhtml/css but ultimately want to master wordpress theming.

    ( Reply )
  39. PG

    James June 1st

    Nice article Gilles! Great for reference in the future! :)

    ( Reply )
  40. PG

    Mark Abucayon June 2nd

    Great points their. thanks for sharing this one.

    ( Reply )
  41. PG

    Colin June 3rd

    Cool Article thansk alot =)

    ( Reply )
  42. PG

    Alexei June 5th

    Great tutorial! Thanks!
    I’ve made translation of this article into Russian for non-experienced in English.
    http://ingeeklog.ru/2008/06/05/structure-of-comments-php-in-wp/

    ( Reply )
  43. PG

    Htoo Tay Zar June 5th

    Great Tutorial!!! Thanks u guys I’ve been looking for WP comments code for a long time. I also want to know how can we change admin comments to unique color? Yep, I saw that style in http://www.smashingmagazine.com. Thanks!!

    ( Reply )
  44. PG

    Rask June 8th

    Thanks! The comments file has always been a mess to work with, this cleared it up a bit. :)

    Htoo Tay Zar: Search for “WordPress author comments styling” with Google, there are loads of tutorials for that. :)

    ( Reply )
  45. PG

    guangyang June 11th

    it’s very very interesting!

    ( Reply )
  46. PG

    Joel Smith June 13th

    Great tutorial! More like these would rock.

    ( Reply )
  47. PG

    Brandon June 16th

    Great tutorial!!!

    ( Reply )
  48. PG

    Filip Růžička June 17th

    Wow, thanks! This helped me a lot today, I’m building my new blog and this was just incredibly helpful. Thanks a lot, great article.

    ( Reply )
  49. PG

    Artem Russakovskii June 19th

    Hi, slightly off topic here, but can you please share what code paste plugin you’re using on your site and if it works with the GUI write mode or do you have to switch to html only? I’m especially concerned with preserving tabs and special characters that genshi seems to have trouble with.

    Thank you very much.

    ( Reply )
  50. PG

    Vadim Zhernovoi June 22nd

    Artem Ryssakovski: i was thinking about seeing this Syntax Higlighter before. After some (not)deep look to the html source, i’ve figured out, that Google Syntax Higlighter as a WP Plugin is used here. You can find it at http://code.google.com/p/syntaxhighlighter/ . Hope it helps:)

    ( Reply )
  51. PG

    Richard X. Thripp June 24th

    Thanks for the tips here. I never liked the default Wordpress comments; I’m bookmarking this to do more hacking on comments.php later.

    ( Reply )
  52. PG

    sdk July 2nd

    concerning the ‘Comments RSS link’ – how would one find the ‘anchor text for the RSS link’?

    thanks

    ( Reply )
  53. PG

    Tommy M July 3rd

    Is it just me, or is the get_avatar function no where to be found in the supplied sample code? I see it in the tutorial but it is not at the link provided at the end of the tutorial. (http://nettuts.s3.amazonaws.com/008_Comments/code.html)

    ( Reply )
  54. PG

    Rex Stevens July 8th

    Thanks for the great tutorial, i have referred back to it several times already. Great work!

    ( Reply )
  55. PG

    ben July 10th

    great tutorial

    ( Reply )
    1. PG

      Kris September 1st

      muy bueno!!!

      ( Reply )
  56. PG

    talizker July 14th

    Great article – thanks very much.

    ( Reply )
  57. PG

    Matt July 17th

    Thanks for this article! Saved my skin!

    ( Reply )
  58. PG

    Paul Madden July 24th

    your link to the code for the example doesnt work sorry!

    ( Reply )
  59. PG

    Gian August 5th

    The tutorial helped me a lot, really, I was struggleling to find a specific tutorial for the comments template for WordPress…

    ( Reply )
  60. This is a great tutorial that helped me thanks.

    ====================================
    http://www.youtube.com/watch?v=E5xhk3__i2o

    ( Reply )
  61. PG

    Joe August 13th

    Any chance you could update the “full code” file you reference above when you have some spare time?

    Great article though, the comments.php file can be a beast if you’re not too familiar with php and how wordpress works.

    ( Reply )
  62. PG

    Windows Themes September 5th

    nice tricks ;) . Thanks

    ( Reply )
  63. PG

    godefroy September 8th

    Loved your article and dugg it.
    I particularly found useful the explanations for each command, for a non-PHP wise person like me it was like subtitles to a Japanese movie.
    Thank you.

    ( Reply )
  64. PG

    Otto September 17th

    It’s worth noting that this guide may soon need a major overhaul. WordPress 2.7 will eliminate most of the needed code from that file and integrate it back into the core.

    Part of this new enhancement: Threaded comments.

    So, basically, as soon as 2.7 is released, every theme’s comments file, while continuing to work, will need a complete rejiggering.

    ( Reply )
  65. PG

    Tristan September 20th

    great job.

    ( Reply )
  66. PG

    Ted October 2nd

    Nicely put Giles. No secrets left in Wordpress comments.php!!
    I’m expecting more quality tutorials from you..

    ( Reply )
  67. PG

    Filip October 3rd

    Sweet!

    ( Reply )
  68. PG

    Wetter October 16th

    Good article. Exactly this I find long time.

    ( Reply )
  69. PG

    Name (required) October 20th

    This is the best css article i’ve encountered so far! You make it so clear and easy to people who are not used to programming. I hope you guys make more css articles for beginners like me. Thank you!!!

    ( Reply )
  70. PG

    Kenny D. October 22nd

    Question…do you think it’s possible to leave comments for multiple Posts on a Home page and only enter the Name, Mail and Website once…and then click Submit, which then submits all the Comments at once?

    ie.
    Name
    Email
    Website

    Post 1 –
    Comment Textarea

    Post 2 –
    Comment Textarea

    Etc.

    Submit Button – click submit to Enter all Comments

    Thanks!

    ( Reply )
  71. PG

    sharon October 25th

    hi nice tut i must say!

    there is a way to use wp scripts as normal php non wordpress script?
    becuse i looking for comment sysem and i loved the wordpress sysem and design
    please email me back

    ( Reply )
  72. PG

    Reynald Bouttard October 30th

    Thanks a lot for your accurate and precious work Gilles.

    ( Reply )
  73. PG

    hostsniper November 3rd

    i like u`r comment styke ! !

    ( Reply )
  74. PG

    benguiyin November 12th

    非常好 谢谢 收藏先

    ( Reply )
  75. PG

    Rayhan Rashid December 17th

    Great article. I was wondering if you could give us some advise. We run a community blog. We are trying to introduce a feature so that all the comments made by any registered author in other blogposts (of our blog) can be shown in one single list. We would be really grateful if you could please advise us or point in the right direction.
    With warm regards.

    ( Reply )
  76. PG

    JenniferLouise January 3rd

    I like the part of having alternate comment colors.

    I made a change to the code to simpify it.

    From yours

    <li id=”comment-”>

    To Mine:

    <li
    style=”background-color:#FFF;”

    style=”background-color:#000;”
    >

    This serves the same purpose without the whole “function” thingy.

    Any way thanks for the great info on the comments.php file.

    ( Reply )
  77. PG

    JenniferLouise January 3rd

    I like the part of having alternate comment colors.

    I made a change to the code to simpify it.

    //From yours
    //
    //<li id=”comment-”>

    To Mine:
    //
    //<li
    //style=”background-color:#FFF;”
    //
    //style=”background-color:#000;”
    //>

    This serves the same purpose without the whole “function” thingy.

    Any way thanks for the great info on the comments.php file.

    ( Reply )
  78. PG

    yaufani adam January 4th

    File> Save As .. :D

    thanks for the tutorial

    ( Reply )
  79. PG

    lucasan January 6th

    Excelente tutorial, directo a los bookmarks.

    Gracias.

    ( Reply )
  80. PG

    Psychedelic January 7th

    thanks good

    ( Reply )
  81. PG

    David January 27th

    When I attempt to leave a comment on a wordpress blog it now stalls at the wp-comments-post.php page with the blank white screen. What is causing this? My comments are no longer being left…. Did I do something?

    ( Reply )
  82. PG

    cory January 29th

    I am wondering if you know of anyway to display the last comment author name in the post main page next to the | 3 comments | link.

    I’d like:

    | 3 Comments Last by %last_author_name |

    ( Reply )
    1. PG

      ninsky March 29th

      yeah, it’s good

      ( Reply )
  83. PG

    Sebass88 February 5th

    Sooo usefull.. i dont know what i would be doing if nettuts and psdtuts didnt exist. i am learning wp for a few weeks and is really easyto customize and theme. by far, the bes blog/cms system ever created.

    ( Reply )
  84. PG

    Franky February 26th

    Awesome this is perfect, this is what im battling now! :D :D:D: Thanks so much!

    ( Reply )
  85. PG

    Ariah Fine March 2nd

    So, I’m wondering if it’s possible to put just the comment form on a separate, additional page.
    I want to create a top frame on external links that would allow a reader to comment on my original post while viewing an external link.
    Like Facebook has on posted items.

    ( Reply )
  86. PG

    sean steezy March 3rd

    I REALLY WISH YOU COULD DO THIS WITH EVERY PH FILE IN WP!

    ( Reply )
  87. PG

    nikola March 13th

    nice tutu

    ( Reply )
  88. PG

    Brent Cornelius March 19th

    I guess Im a complete newb, but can someone explain how I would style this with CSS.

    ( Reply )
  89. PG

    tabu March 23rd

    tabu

    ( Reply )
  90. PG

    Pinoy Top 10 March 24th

    Thank you. I did not know how simple it is until I saw your post.

    Very helpful indeed.

    ( Reply )
  91. PG

    Stephen Clark March 30th

    The link to the HTML file is broken and the comments.php file at the end is not the correct code. Could someone at NetTuts update these please?

    ( Reply )
    1. PG

      J May 3rd

      Great tutorial. Thanks!

      ( Reply )
  92. PG

    Filipino March 31st

    You did a great detailed tutorial for all. Thank you.

    ( Reply )
  93. PG

    Frederik April 14th

    Thanks for this awsome tutorial. I wish more people did such a great job, so I would waste my time on the internet with some useful stuff ;-)

    ( Reply )
  94. PG

    e April 14th

    i love the style of your comments area

    ( Reply )
  95. PG

    AJTOGC April 18th

    Thank you, this is really helpful. You rule.

    ( Reply )
  96. PG

    Adam Winogrodzki April 20th

    Thanks its a great Thing !

    ( Reply )
  97. PG

    Kate Mag April 21st

    Wow unraveling the secrets of WP’ comments indeed!
    The best tutorial about WP comments so far

    ( Reply )
  98. PG

    Chuck April 29th

    Great stuff – your mods should be included by default in the WP package.

    ( Reply )
    1. PG

      Michele July 28th

      I agree :)

      ( Reply )
  99. PG

    Victor May 8th

    Excellent Tutorial – Thanks

    ( Reply )
  100. PG

    Mike May 10th

    Very detailed tutorial thanks a lot!

    ( Reply )
  101. PG

    Jay Reynolds May 19th

    this is a great tutorial! after following… i’m still having issues. I was curious if someone could help me out. I’m working on a website, and I’m having trouble with comments.

    My comments are continually showing on “1 post”. It does not matter which post I try to comment on, everything goes directly back to the same “1 post”.

    I’m a noob at php… can someone offer some help, please?

    http://www.gethopestudents.com/another/ (receives all the comments)
    http://www.gethopestudents.com/bigstuf/ (example of a post i’m trying to test comments)

    Thanks!

    ( Reply )
  102. Молодец! Целиком поддерживаю! :)

    ( Reply )
  103. PG

    MAЙЯ May 24th

    Занятно. Чувствуется Ваш позитив :)

    ( Reply )
    1. PG

      Test June 23rd

      Test

      ( Reply )
  104. PG

    Наум May 28th

    Так без недостатков и достоинства незаметны :)

    ( Reply )
  105. PG

    etomyam June 9th

    interesting..how can I edit my comment form just like you did it here….

    ( Reply )
  106. PG

    AnneMarie June 18th

    This article was very helpful. Is there a way to control how many comments per page? would this be put into the comments.php?

    ( Reply )
  107. PG

    Tarek June 20th

    great, you are the best.

    ( Reply )
  108. PG

    Mixas June 25th

    Thank you.
    I will make attempt bind to the site.

    ( Reply )
  109. PG

    Himiko June 27th

    Excelente tutorial, directo a los bookmarks.

    ( Reply )
  110. PG

    tinaung July 10th

    ho ho
    so good
    Thank you.

    ( Reply )
  111. PG

    sam July 18th

    very good.
    thanks

    ( Reply )
  112. PG

    Some0ne July 18th

    Great tut just what I was slooking for but…this line:

    Logged in as <a href=”/wp-admin/profile.php”>. <a href=”/wp-login.php?action=logout” title=”Log out of this account”>Log out »

    will cause an error when trying to log out, it must be changed to:

    <?php printf(__(’Logged in as %s.’), ‘‘.$user_identity.’‘); ?> <a href=”" title=”">

    ( Reply )
  113. PG

    keidi July 24th

    Ok, I don’t know php. But I will learn it now.

    ( Reply )
  114. PG

    Anna Jane July 28th

    Thank you SO much for this! I was literally surprised at the apparent lack of articles out there covering how to change the wordpress comments templates. You’re a real star. thank you once again.

    ( Reply )
  115. PG

    Michele July 28th

    Wow this website has tought me so much! Thank you so much for your tutorials!! This is the BEST site on the web.
    You saved me so much time. I appreciate all of your hard work!

    I bookmarked your site and sent it to all my friends.

    Again thanks so much!

    Michele

    ( Reply )
  116. PG

    Saniska August 1st

    Присоединюсь к предыдущим комментариям и буду следить за дальнейшими обновлениями

    ( Reply )
  117. PG

    Gliska August 1st

    Решил добавить RSS и получать новости, мне лично понравилось, что написал автор

    ( Reply )
  118. PG

    yarim ezgi August 3rd

    very useful tutorial.regularly i m reading.thanks

    ( Reply )
  119. PG

    dayan August 18th

    Thank you very much, It’s very useful !

    ( Reply )
  120. PG

    vunteebeeta August 24th

    lahv hdmi audio driver :-) tka
    fqhdg realtek ac’97 audio driver download :-) jrv
    qadil twain driver :\ kno
    rvqgx driver game :0) kqps

    ( Reply )
  121. PG

    Ian Cleary August 31st

    Hi, thanks for this really helpful.

    ( Reply )
  122. PG

    jaun September 1st

    Great !!

    ( Reply )
  123. PG

    Yheng September 9th

    Just found what I am looking for, thanks Gilles! Very informative.

    ( Reply )
  124. Nice Article..

    I’m currently doing upgrade for my comment form…. on one of my client project…

    this helped me lot to understand each line of comment.php for wordpress

    thanks

    Regards,
    Affordable Wordpress Hosting

    ( Reply )
  125. PG

    PaylasimCity September 17th

    nice post,thanks so much :)

    ( Reply )
  126. PG

    Alex September 26th

    Thanks for this tutorial.

    Can you not use these comment functions within a page of posts? For some reason mine is not working, and I am placing the functions within the loop.

    ( Reply )
  127. PG

    Liam September 28th

    Can someone explain how to style the comments like those seen here on nettuts?

    ( Reply )
  128. PG

    ColorMySky October 8th

    Hello and thank you for writing this. I CANNOT for the life of me figure out why my comment textarea is extending all the way to the right. I have tried everything to limit it to about 75% of the div it lies within and have failed. Please help!

    http://www.colormysky.com

    ( Reply )
  129. PG

    Dean October 27th

    Awesome, Thanks!

    ( Reply )
  130. PG

    LK October 29th

    Very, very useful. Well-written. I only wish I had found the tutorial sooner. It would have saved me a lot of time. One wish for an enhancement though: you also provided a solution for alternating row background colors. A solution for highlighting author rows would be very helpful. I have found tutorials on author highlighting. Unfortunately they are written assuming there is already underlying code in the comments.php and then they don’t show you the underlying code. The code appears to be dissimilar from your alternating rows solution, and so I haven’t been able to get it working.

    ( Reply )
  131. PG

    veapon October 30th

    Great tutorial~
    Learn a lots from here~

    ( Reply )
  132. PG

    Cottelletje November 3rd

    how can i get an comment style css and code for the style that is used on this site please? can anybody mail it to me?

    ( Reply )
  1. Arrow
    Gravatar

    Your Name
    November 3rd