WordPress 2.7 Comments Enhancements

This post has been moved here: http://ottopress.com/2008/wordpress-2-7-comments-enhancements/

WordPress 2.7 includes a lot of new enhancements, but one of the big ones is the new comment functionality. Comments can be threaded, paged, etc. This is all built in, but unfortunately, your theme must support it. So, for theme authors, I’d suggest getting to work on making your themes compatible right away.

Read on if you’re a theme author…

Note: A lot of people seem to miss this key bit: Enhanced Comments are optional and default to off, even after you make these changes. You have to go to the Settings->Discussion panel to turn the features on.

Actually “compatible” is not quite the right term. Old themes will continue to work fine in WordPress 2.7. It’s just the threading and paging and javascript enhancements need the theme to support it. This is much the same as the sidebar widgets, the theme has to support it for the functionality to work. So this article is really not about 2.7 compatibility, it’s about 2.7 capability.

Note that this article will explain some of the changes needed to make themes capable of supporting the new comments functions, however there’s no substitute for the real thing. Install a local copy of WordPress trunk on your home machine (possibly using XAMPP) and test it there.

Also note that this is all based on the current state of WordPress trunk, and is subject to change before WordPress 2.7 is released. However, it’s probably not going to change all that much at this point.

How to create a 2.7 compatible comments.php

2.7 Detection

If you want your theme to be backward compatible as well, then there’s a simple way to do it. Just check for the wp_list_comments function, like so:

if (function_exists('wp_list_comments')) :
// new comments.php stuff
else :
// old comments.php stuff
endif;

While you could check for the version number of WordPress, this method is better because it simply looks for the actual function you’re going to use anyway. Never make assumptions based on version number.

One of the more interesting ways I’ve seen to use this is to have the “old comments” php in a separate file entirely, which is then included. This preserves backwards compatibility for your theme in a simple way. Here’s a quick example code for that approach:

<?php
add_filter('comments_template', 'legacy_comments');
function legacy_comments($file) {
	if ( !function_exists('wp_list_comments') )
		$file = TEMPLATEPATH . '/legacy.comments.php';
	return $file;
}
?>

Adding this code to a theme’s functions.php file will make the theme use the “legacy.comments.php” for older non-2.7 installations. That way, you can simply rename your old comments.php and then make a new one based on the new functionality. Clever.

Password Protection Check

Put this code at the top of your comments.php file. This is what lets it support the post password functionality. Note that this code is quite similar to the previous way that it was done (by checking the cookie directly), but now WordPress has a specific function to do it. You should use this function in case the functionality changes in the future, your code will be forward compatible:

if (!empty($_SERVER['SCRIPT_FILENAME']) && 'comments.php' == basename($_SERVER['SCRIPT_FILENAME']))
	die ('Please do not load this page directly. Thanks!');
if ( post_password_required() ) {
	echo 'This post is password protected. Enter the password to view comments.';
	return;
}
<h4>The Comments Loop</h4>
The Comments Loop used to look similar to this (much simplified from a real one):
[php]if ($comments) :
<?php $comment_count = get_comment_count($post->ID); echo $comment_count['approved']; ?> Comments
<ul class="commentlist">
<?php foreach( $comments as $comment ) :
// stuff to display the comment in an LI here
endforeach;
?></ul>
<?php else :
if ('open' == $post-comment_status) :
	// If comments are open, but there are no comments.
else :
	// comments are closed
endif;
endif;

Basically, it went through the comments manually and output all the necessary pieces. Easy, but very manual. This also had the problem of being very inconsistent and hard to manage for your theme’s users, especially if you heavily customized it.

The new comments loop is much simpler:

<?php if ( have_comments() ) : ?>
<h4 id="comments"><?php comments_number('No Comments', 'One Comment', '% Comments' );?></h4>

<ul class="commentlist">
<?php wp_list_comments(); ?>
</ul>

<div class="navigation">
<div class="alignleft">< ?php previous_comments_link() ?></div>
<div class="alignright">< ?php next_comments_link() ?></div>
</div>
<?php else : // this is displayed if there are no comments so far ?>
	<?php if ('open' == $post->comment_status) :
		// If comments are open, but there are no comments.
	else : // comments are closed
	endif;
endif;
?>

That new one is, in fact, a complete comments loop. No simplification at all. Unless you want something displayed for “no comments” or “comments closed”, of course. I don’t have anything showing there.

There are three important pieces to note here:

  • The have_comments() function replaces the check on the global $comments variable.
  • The wp_list_comments() function now outputs all the comments. It does threading, the classes, everything new.
  • There’s a new navigation section to do comment paging.

The Power of Javascript

To support the new Javascript functionality with comment threading, some minor bits of code are needed:

First, in the header.php, add this line immediately before the call to wp_head():

if ( is_singular() ) wp_enqueue_script( 'comment-reply' );

That code adds the comment-reply javascript to the single post pages, letting the comment reply links work correctly. WordPress specifically does NOT do this itself, for the reason that use of this script requires certain naming conventions and parameters in the comment form, which you’ll have to add.

So, your comment form has a new parameter that you have to add:

<?php comment_id_fields(); ?>

This adds a bit of code to your form which makes it display two hidden inputs: comment_post_ID and comment_parent. Your form probably had the comment_post_ID before, so you need to remove it. The comment_parent is there for the javascript, so that replies to comments get threaded properly.

Also, your comment textarea MUST have an id=”comment”. The javascript expects it for focus purposes. If you used anything else, change it. Note that because of this, no other element on your page can have the “comment” ID.

Finally, the entire comment form MUST be surrounded by a DIV with an id=”respond”. In some previous themes (including the default ones), there would be an anchor tag like this:

<a id="respond"></a>

This was there to allow the link from the front page to go directly to the respond section when there were no comments already. That still happens, but now there’s a double purpose. The javascript moves the comment form to where the reply link is, so instead of it being an anchor, it needs to be a DIV that surrounds the comment form.

So, remove that anchor, and add a DIV with an id=”respond” around the entire comment form. The link from the front page still works this way with all modern browsers, and the javascript can now move the form around on the page as needed.

Next, you can replace the call to your normal “Leave a Comment” text with something like this:

<h3><?php comment_form_title(); ?></h3>

This makes a comment form title of “Leave a Reply” which will change to “Leave a Reply to Whoever” when somebody is replying directly to another person. You can customize this, if you like, with two parameters, like so:

<?php comment_form_title( 'Leave a Reply', 'Leave a Reply to %s' ); ?>

The %s will be replaced with the person’s name. This will only happen when the javascript isn’t working and the reply links have to cause a page refresh. So it’s usually not worth customizing much. Still, not everybody runs javascript and so this is nice to let them know who they are replying to.

Finally, you’ll notice that when somebody clicks “reply” and the comment form appears there, maybe they decide to cancel instead. So, that cancel link needs to be in your respond section. Here’s the code to do that, just put it right below your “leave a message” header in the comment form area:

<div id="cancel-comment-reply">
	<small><?php cancel_comment_reply_link() ?></small></div>

That’s pretty much it for making the AJAX work. With this, the new features on the Settings->Discussion panel will work. Obviously, you can modify this somewhat as needed for your theme, these are just general principles that you’ll need to use.

Styling

Now that you have it working, there’s plenty of new styling you can add to comments. The new comments loop automatically puts every comment into an LI tag, and threads them as well, with embedded UL/LI tags. It also adds a ton of classes on all these LIs which surround every comment in this fashion:

  • comment, trackback, pingback classes get added depending on the type of the comment.
  • byuser gets added if the comment is by a registered user of the site.
  • comment-author-authorname gets added for specific registered users.
  • bypostauthor gets added if the comment is by the author of the post the comment is attached to.
  • odd and even classes are added to odd and even numbered comments
  • alt is added to every other comment
  • thread-odd, thread-even, and thread-alt classes are the same as the odd/even/alt classes, but these only apply to the top level of each set of comments and replies
  • depth-1 is added to the top level comments, depth-2 to the next level, and so on.

What’s more, a comment_class filter is provided to allow you to add your own classes. Here’s an example of that. This example function adds a microid to every comment with the microid for the comment authors given URL and email address. This sort of thing could be done in a plugin or a theme’s functions.php file, whatever.

// add a microid to all the comments
function comment_add_microid($classes) {
	$c_email=get_comment_author_email();
	$c_url=get_comment_author_url();
	if (!empty($c_email) && !empty($c_url)) {
		$microid = 'microid-mailto+http:sha1:' . sha1(sha1('mailto:'.$c_email).sha1($c_url));
		$classes[] = $microid;
	}
	return $classes;
}
add_filter('comment_class','comment_add_microid');

Simple and effective. It just adds the class to the given array of classes and lets the comment display functions take care of the rest.

And there you have it. It’s not hard to support the new functions. And if you need to customize your theme’s comments section even more, wp_list_comments() supports a number of parameters. Most of this is not documented yet, because WordPress 2.7 is not out until November. However, the code is relatively straightforward, and anybody with a good understanding of WordPress should be able to work it out.

Additional: A lot of people keep asking me for a full-fledged example. Really, I recommend that you examine the comments.php file in the default theme in the 2.7 beta versions. However, the actual comments.php file I’m using on this site can be found here: http://ottodestruct.com/comments.phps, if it helps you any. It has the code I’ve described in this article, pretty much verbatim. The only additions to it are a couple of extra options on the wp_list_comments() call, such as avatar_size and reply_text.

This entry was posted in Geekery, Hackery, Programmery and tagged , , , , , , , , , . Bookmark the permalink.

407 Responses to WordPress 2.7 Comments Enhancements

  1. Jess Planck says:

    Awesome as usual Otto! Of course I have to make a comment to see it in action!

    • Otto says:

      I haven’t done a lot of styling yet, but you can at least see some of it here, what with the threading and my comments being a bit more blue than yours (thanks to the bypostauthor class).

      • I wonder how replies to replies would be handled…

        • Jules says:

          Here is a reply to a reply, cause I was also wondering…

          Thanks for the great writeup!

          When is 2.7 supposed to be released?

          • Looks like this could turn out to be really tacky, is there a way to disable it?

          • Otto says:

            Define “tacky”, exactly? If you’re talking about the style, then that’s entirely up to you. I made my comments a bit tacky to sort of demonstrate how it works. I was not too concerned with style. :)

            But yes, even with the new comments functionality, there’s several options on the Settings->Discussion page. You can enable/disable threading, put a limit on how deep the comments can thread, number per page, choose the ordering (newest first, oldest first), etc, etc…

            But none of those options work until your theme supports them like this article describes.

          • That’s good because I was worried this new “featured” would fuck up my theme that I am working on.

        • Allpa says:

          I ask to forgive my poor English – I live in Ukraine, I use the program-compiler: (

          At me all has turned out, except one – comments turn out NOT threaded though the necessary point in options WP is noted.

          And it just what I try to achieve from comments in a blog http://allpa.ru/- what to do? How to rectify situation?
          Very much I hope for your help…

          It would be desirable to allocate still comments of the author of a blog with other colour how it is made at you – you could not prompt the necessary actions?

          Thanks!:)

  2. Ozh says:

    Very good article, thanks for this!

  3. Pingback: Get Your WordPress Theme Ready For 2.7 « planetOzh

  4. JD Hartley says:

    Thanks, Otto. Will implement this into my site’s theme. :)

  5. Ptah Dunbar says:

    Wow, you guys did a lot of work, hopefully all the themers will take advantage of all these new features for comments. I’m guessing all of the code you mentioned here is build into the default theme right?

    • Otto says:

      Yes, the default theme uses this new functionality and shows this stuff off fairly effectively. The old theme comment methods will still actually work, however the new functionality (thread, paging, AJAX, etc) won’t work until the theme is modified to do it this way.

      Here’s the trac ticket where all these enhancements were added along with who added them: http://trac.wordpress.org/ticket/7635

  6. Excellent advice, thanks.

  7. DD32 says:

    Just one little nitpick: “AJAX”? Its not Ajaxified by default at all, just Javascript to move the reply form, You dont want to confuse people now do you..? :P

    Hopefully this article will be useful to theme developers though, It can be a bit confusing at first following the default themee layouts.

    • Otto says:

      Bah. I suspect that it will become more AJAXified as time goes on. I can see comment replies getting put onto the page without a refresh, for example. That would be pretty cool.

  8. Jared henderson says:

    You’re a beast! Thanks for this. …back to work.

  9. Pingback: WP 2.7 Comments Enhancements :: WPLover

  10. Ajay says:

    Hi Otto,

    The article is great. Can you add a sample comments.php ?

  11. A sample comment file would be especially helpful for those of us who have a theme made by someone no longer available to modify. So we have to middle through.

    Also how would we deal with an existing quoting plugin and the new features?

    Explain, please, for the PHP-challenged.

    Peace,
    Gene

    • Otto says:

      The default theme has implemented this into it as of 2.7. I have not checked the classic theme, but it will likely get the same treatment.

      As for how you’ll deal with the plugin, well, it really depends on the plugin. This new code makes many plugins obsolete, however the old style of comments still works fine, so if you want to keep using plugins instead of the new stuff, you can.

      • Quoter, no longer being updated, gives each quote a specific number, so only that item appears in the comment, even if it’s not the previous message.

        I wouldn’t mind this Reply function instead, and disable that plugin, but then I’d have to find a way to do a wild card search to eliminate the extra code in the blockquotes. Do any of the search and replace plugins accomplish that?

        This would be a viable solution. Our standard comments theme file is very close to the default/classic ones, with only minor changes I can, as PHP-deficient as I am fix.

        I’m not averse to removing plugins that’ll no longer be needed.

        But this is the lone issue I’ll need to consider.

        Peace,
        Gene

        • Otto says:

          You could probably figure out a way to script it and convert.

          If you have any way to determine which comment number the quote came from, then you can thread your comments. The comment threading works by including a comment_parent value with each comment. The contents of that column is the comment_id of the parent. So if your quoter has that, then you write a script to:
          a) remove the quote
          b) save the comment_id value of where the quote came from in the comment_parent

          And voila, threading.

  12. Pingback: Anticipating WordPress 2.7 | Web Weavers Workshop

  13. Tinh says:

    it is quite complicated process

  14. Li-An says:

    This means I will have to do some work on my comment.php ? Oh, no, my God !

  15. Pete says:

    Thanks Otto, good insider information as always!

  16. Will says:

    Thanks for the great tips.

    I would like to know if with the new features, can I still separate trackbacks from comments? And also, how do I go about making my comments threaded, or is it already integrated with the new function?

    Again, thanks for your help.

    Will
    http://will.ph/

    • Otto says:

      Yes, the wp_list_comments function takes a “type” parameter to get different types of comments. It defaults to “all”, but it can also be: comment, trackback, pingback, or “pings” for both trackbacks and pingbacks combined. So wp_list_comments(‘type=pings’); would give you all the pings.

      Also, as you can see, the trackback/pingbacks can be integrated but styled differently. I made them yellow here for purposes of demonstration. I need to sit down and restyle my comments sections, actually. ;)

      Threading is handled automatically, and in the Settings->Discussion area, you can set a depth parameter, with how many levels deep you want the threading to go.

      wp_list_comments takes several arguments, which I did not go into because most themes won’t (or should not) use them. However, it is as configurable as everything else when it comes to styling and such.

  17. Aw Guo says:

    Awesome. My theme could be even better than before with this power :)

  18. You said: “Also note that this is all based on the current state of WordPress trunk, and is subject to change before WordPress 2.7 is released.”

    My question is this. Is there a place that I can check before installing the 2.7 update to know how to bring my theme up to par?

  19. Jess Planck says:

    It took me a little while to test out, but it works great so far on my test site! I thought I would mention that you MUST set a thread level in the Discussion settings AND check the “Group replies” option. Otherwise it will default to 0 and you will not see threaded comments or reply links even if you have the “Group replies” option checked.

    • Otto says:

      Actually, if you leave it blank (not zero), then it defaults to -1, which is unlimited levels of threading. That should probably be clarified there somehow.

  20. Will says:

    Hi Otto,

    I have another question. Would the function “have_comment()” accept a parameter such as type=pings so one can easily separate comments from trackbacks/pingbacks?

    Thanks again for the tips.

    • Otto says:

      No, it doesn’t, but that is a good idea.

      • Monika says:

        Hi Otto if I can separate comments from pings I’m very happy.

        Threaded comments are not my favour and if WP 2.7 comes I have less possibilities to design them,
        because css doesn’t accept 6 different styles in one class.

        how can I add divs to design the author or the meta section of comments?

        kindly regards
        Monika

        • Otto says:

          I’m not entirely sure what you mean by CSS not accepting styles/classes. Styling your comments is very very easy with this code.

          If you look at the code, the author data gets encapsulated inside a div with a class of comment-author. The meta data gets put inside comment-meta as well as commentmetadata. This is automatic, you don’t need to change a thing to get it.

  21. Pingback: Synesthesia » Links roundup for 2008-09-30

  22. Lee says:

    One thing I really think about WordPress 2.7: it is such a massive overhaul to so many aspects of WordPress (with a lot of potential for compatibility issues) that I think it should be called WordPress 3.0, with the 2.6 branch maintained for security fixes. I am actually very happy with how I’ve gotten Sachiko’s blog (I am her webmaster) running with 2.6 and the combination of plug-ins that we have, and I can see a lot of this will be broken in 2.7. That will probably be worth it in the long run, but I suspect it will be quite a while before I am able to upgrade.

  23. Iva says:

    This is splendid. Thank you so much.

    BUT…if I had used one of the paged threaded comment plugins before, how will switching to a built-in facility of the same kind affect my old comments?

    • Otto says:

      Really depends on how the old threading plugin worked. If it used comment_parent, then the threading will persist. If not, then you’ll probably lose that threading info from the old comments.

  24. I’m really excited to see how 2.7 comes across. There have been a lot of minor issues with 2.6 that I wasn’t overly impressed with but I think if the new framework is anything to go by, this is going to be great.

  25. Quentin says:

    I wanna try cause it’s really exciting

  26. Guillaume says:

    Great news, thanks.

  27. Andrew says:

    There are some updates/changes to the comments reply functionality and template tags. Now it supports replying without JS too. Some more info: http://wpdevel.wordpress.com/2008/10/11/some-changes-and-improvements-to-threade/

  28. Rahul says:

    Oh my my… this is a hell lot of coding for a geek like me. Isn’t there any simple just one click solutions. Man… I want to try out these functions as well. but, what if anything goes wrong…

  29. Ahmed says:

    Correction:
    Thanks a lot for this detailed guide. I couldn’t make it work by just following the steps above.
    I think you need to ad the following line to the comments form after the hidden field:
    comment_parent_field();

  30. Francis says:

    Is there a way to change “Reply” by something else ?

  31. hi

    btw, you can just try wp 2.7 on my blog: wp.blogywalkie.com. Use “test” as your password and username

    this is very new, wp2.7 on my blog is prototype version. only few blogger has coppy of it,

    include me. check it out guys!!!!

  32. Roon says:

    Have been debating whether or not to design my own theme from scratch, as I build sites everyday at work!

    But after reviewing some of the new features of 2.7 think I might start build specifically for that.

  33. Byron says:

    Hi Otto,
    Thanks for the how-to! I am excited about the new comment features. Particularly threaded comments. I was beginning to consider a plugin like JS-Kit until I heard about the new features.

    Excellent work!

    Byron

  34. Branch says:

    This is lovely, I was just struggling with making the foreach loop do a bunch of these things, and now it will come integrated. This is good!

    I have a question, though. Clearly get_avatar or similar is being used inside wp_list_comments, yes? Is there (or is there going to be) a way for plugins to override that function? Because all the alternate-avatar plugins I’ve seen rely on manually inserting a function call in comments.php, and obviously that won’t be possible using wp_list_comments.

    Also, do the new threaded comments come with email notification to the parent-comment author? I suppose this may be answered if/when you reply, of course!

    • Otto says:

      Must be some older plugins then, because they’re doing it wrong.

      get_avatar() is a pluggable function. Meaning that any plugin can override it entirely by simply making a new get_avatar() function in their own code, that takes the same parameters as get_avatar does. If they’d rather not handle all cases, it has a get_avatar filter on the result, so that a plugin can override or modify the output from the normal get_avatar function. Any avatar related plugin should use these instead of requiring the user to modify their theme manually.

      Also, I don’t think notification is built in at this point, but it could probably be easily done in a plugin.

      • Branch says:

        Yes, they were older; I think I’ve figured out how to modify them, though. Thanks!

        One thing I’ve noticed, while going through the new comment structure, though. The lack of a class on the div that encloses each comment (the one that gets id=div-comment-xxx where xxx is the id number of the comment) is going to severely impair some css layout options. If that particular div could be given a class (comment-div or something) that we could use in conjunction with .odd, .even, etc. that would open up the options again. I realize you guys are in bug-swatting mode rather than feature mode, but, as a layout designer, I consider this a fairly significant bug.

        Cheers

        • Otto says:

          What, exactly, does that prevent you from doing? Because that particular DIV is easily referenced directly by simply using “ul.commentlist li div”. There’s no need to add classes on something that is directly referencable without them.

          In fact, classes only are ever necessary when you’re dividing things into more than one of something, not when ALL of that thing are the same.

          You can even reference that div differently for pingbacks, comments, trackbacks, etc, like so: “li.comment div”, “li.pingback div” and so on.

          • Branch says:

            All I can say is that I’ve had problems with similar configurations in the past. If what I want is to, say, give even and odd different background colors, but only around the body of the comment so that the colors don’t nest as the thread goes on, sometimes I’ve run into problems when I reference an unclassed element that’s inside nested classes; the most proximal class is supposed to take precedence, but sometimes the result I get is as though the browser processed it in a different order and decided that all divs inside .even (which means the entire thread) take the even class. This without an inherit order to be seen anywhere. Drove me absolutely nuts. If the element I reference has a class I can use instead of just the element type, that seems to work most reliably.

            Speaking of which, though, I had another thought about the classes while looking at the html here. It seems like ‘byuser’ and ‘bypostauthor’ and ‘comment-author-[name]‘ show up in strange positions. Those should come last, yes? Since they are the most likely to need to override other classes? Looking at the source code here, the three in question appear right after ‘comment’, when they appear.

            Cheers

          • Otto says:

            Yeah, I follow you with the class thing now, browsers can be problematic in that way. Still, the spec is pretty clear. And there’s CSS tricks to get around those particular browser issues, if/when they crop up.

            I’m not sure what you mean though with regard to the class ordering. Class order in the element is unimportant, because overriding of attributes happens depending on the order in the CSS file itself. Later elements in the CSS processing cycle override earlier ones. Classes in the HTML are all considered equal, and order doesn’t matter there.

          • Branch says:

            Order does seem to matter. If there are multiple classes listed on one element, and more than one of them is defined via css, then the latest class in the string will be the one that takes precedence, no matter what order the classes are defined in, in the css file. This may vary from browser to browser, but in FF on mac, at least, that’s how it’s working.

            So, for example, I’ve defined even and odd and bypostauthor. No matter what order I put them in on my style.css, bypostauthor does not take effect. (I’m currently playing with a nightly build to test this stuff out.) I’ve been able to get around this by using li.bypostauthor, but wouldn’t it be better to line the classes up in a good order of precedence to start with?

            And, um, if you know a css trick to make that enclosing div take a style without applying it to every other div inside it, could you tell me? I have yet to find a way around that one. If I have to do up a function to add the class just for my own theme, I think I can, but a purely css answer would be better.

            Cheers

          • Otto says:

            Well, if that’s really the case, then your Mac is broken and it is doing it wrong. I cannot duplicate your results in Firefox on Windows/Linux, or IE on Windows. Furthermore, the CSS specification explicitly spells it out the way I’ve said it.

            In actuality, it’s somewhat more complicated than this, but it’s really a matter of specificity. The last rule in the processing chain which is also the most specific rule takes precedence. Equally specific rules (bare classes would be equal) means that the last one counts.

            So, are you sure that you don’t have a more specific rule overriding your other rules here? Even if it’s higher in the file, more specific rules win. The way you describe it, it sounds like you do. Note that li.bypostauthor is more specific than the generic .bypostauthor. And the key to your problem is that a specific rule targeting the comment li’s would likely be in between those two…

            As for your CSS problem, I suspect you’re using the wrong CSS Selectors. Google for “CSS Selectors”. If you don’t want deep children, you don’t have to select them. Like so:
            li.bypostauthor > div { background-color: red; }

            See? The > means to only select the div that has an immediate parent of li.bypostauthor. Simple, eh?

  35. Pingback: WordPress Wednesday News: WordPress 2.7 Soon, Security Upgrade, PodCamp-WordCamp Hawaii, PollDaddy, and More | The Blog Herald

  36. Monika says:

    Hi I’ve read that someone has trouble with css classes – css doesn’t support more than 4 classes in a div

    class = 1 2 3 4 and than it is over and out so most of the new classes are not useable for theme authors
    and if you define 1 with color black and 4 with color green -green is the winner ;) so you must be a css guru to style comments individual – I’m sure most of the themes would like very *creative* and our support forum full of *help me!* posts ;)

    but I have a question to: Password Protection Check

    is this backwards compatible? if not how can I make my themes for free backwards compatible?

    thanks a lot

    Monika

    • Otto says:

      Dunno where you got that idea, but there is no inherent limit to the number of classes that you can add to any element, DIV’s included. The only limitation is browser coding and memory. Modern browsers support well over 2000. I am actually using some of those “past 4″ classes for styling on this very site. With all these classes, styling comments individually is actually quite easy, no “guru” status required. :)

      The post_password_required() function is new to 2.7, so it is not backwards compatible. If you look at the default theme in 2.6, then you can see the older way to do it. If you want to make this piece backwards compatible, then you can check for function_exists(‘post_password_required’) and use it if that returns true, or use the old way if it returns false. But it is important to use post_password_required() for future forwards compatibility.

  37. Pingback: Making your theme’s comments compatible with WordPress 2.7 | Jnbn.Org

  38. Scott says:

    I can’t fault the tutorial – but I found it easier installing the beta and modifying the comments.php in the default theme :-)

    I’ve successfully(!) styled the threaded comments, but where do the numbers come from? You can see the comments on my site at the bottom of this page.

    I also can’t sort out anything to hide the comment form using javascript, and have it appear when a link is clicked.

    • Monika says:

      Scott the numbers are from the ol list

      div#comments ol.comments{ list-style:none;}

      and than there are no numbers

    • Otto says:

      Scott: As Monika suggests, the OL’s are creating the numbers.

      As for the javascript, I’m not sure what you’re talking about. The form normally shows up at the bottom, and then when you click a reply link, it moves to where that link is. I can’t test it myself, because your site seems to require a login to reply.

      • Scott says:

        Cheers for both your replies – I knew it would be something rather straight forward!

        The form is present at the bottom, and moves to the reply link when clicked, but I misread what was supposed to happen – I thought that the comment box was hidden altogether until “post comment” is clicked, but that isn’t :-) So ignore me!

        Thanks again for the replies though.

  39. Pingback: WordPress 2.7 Beta 1 | Michael Aulia -Technology and Reviews

  40. Pingback: WordPress 2.7 Beta 1 » will.ph

  41. nkuttler says:

    Hrm, I think the next_comments_link() function breaks when you activate paging + click on a previous or next page link. The url ends up being http://domain/page/comment-page-3/?replytocom=89/comment-page-2/#comments. Can somebody confirm this? Just append some GET parameter and follow a next or previous comments page link.

  42. Pingback: Comment paging in WordPress 2.7 - nkuttler

  43. nkuttler says:

    Actually, forget what I said. It was an error in my template it seems.

  44. Pingback: WordPress 2.7 Updates — WPCandy — WordPress Themes, Plugins, Tips, and Tricks

  45. Tim says:

    How is Gravatar support enabled in the new comments loop? I currently have this piece of code:
    echo get_avatar( get_comment_author_email blah blah

    • Otto says:

      You don’t have to do anything. wp_list_comments will make the correct call to add the gravatar as needed. If you have the gravatars disabled in the admin area, then the avatar won’t be added.

      • Tim says:

        Thanks Otto.

      • Zain says:

        Hi Otto,

        Great post – very interesting read. I’m actually wondering what happens if you *do* want to change the default Gravatar size? I’m currently playing with WP2.7b3 and there doesn’t seem to be any options to change the default Gravatar size. I’ve looked under a variety of options (discussion settings, media etc.) and can’t find anything…

        Aside from switching it off and on, do you know if the an option to resize the Gravatar will make it into WP2.7 public release?

        Thanks,

        Zain

        • Otto says:

          Zain, the option name you are looking for is “avatar_size” and it’s mentioned in several other comments on this page. You cannot change the size in the admin, and no, no option will be given to do that. The size of the avatar is properly a theme controlled item, as that affects the style and design of the page itself.

          • Zain says:

            Thanks Otto.

            S’okay, I found it… and a few interesting other features too, like the reverse threading; child reverse threading; separating out comments from trackbacks, controlling the number of comments per page; the text for the reply link as well as the avatar size!

            Will document it when I have a little more time.

            Thanks for the great post. And I get your point about the size of the avatar being theme controlled.

    • manju says:

      How is Gravatar support enabled in the new comments loop? I currently have this piece of code:
      echo get_avatar( get_comment_author_email blah blah

      • Otto says:

        Avatars are included in the wp_list_comments, you don’t need to call them manually. Just turn them on in the Settings->Discussion screen.

  46. Pingback: Wordpress 2.7 - Sort our your comments | wordpressguru.eu

  47. Darran says:

    Up till now, I have created my theme to be handling AJAX commenting. But with paging and threading, it is just not going to be that straightforward. It could most probably be done with some extensive checks but it is the paging which is breaking everything apart. Is there a way we could retrieve the number of comments per page via JavaScript?

    Also when will documentation on the wp_list_comments() be released? I want to be able to customize how my comments are listed.

    • Otto says:

      In order for the javascript to have that value, you’ll have to retrieve it and put it in the page somewhere, as a script. In PHP, you can get that value like so: $per_page = (int) get_query_var(‘comments_per_page’);

  48. Pingback: Are your theme’s comments WordPress 2.7 compatible? | Wordpress Blog NL

  49. Marcel says:

    Thanks for this post, this is the information that I was looking for.
    I am just working on comment enabling for my image gallery.

  50. Pingback: Socializing a WordPress site | geek ramblings

  51. Andy says:

    Hi, I’m ‘feeling my way’ through making the changes, and seem to have everything working – but it’s driving me slowly mad trying to find out in which file the wordings are located – by which I mean, ‘Reply’ as one example. I want to change that from the default, and can’t find any reference to it in the comments.php file. I know it will be found in another php file somewhere on my server, but which one, please? I’d be grateful for the help as the ‘Reply’ text appears fine, with good spacing, if I’m not logged in but I use a plugin that provides ‘on the page’ editing of the comments, and with the links that provides appearing, the ‘Reply’ link appears somewhat squished, way too close to the other text. So I’d like to insert a line break.

    • Otto says:

      In WordPress, higher level functions like wp_list_comments() tend to pass the arguments they receive down to lower level functions. In this case, the get_comment_reply_link() function is what creates that text, and it has a parameter of “reply_text” that will let you change that. Because of this argument passing, that means that you can send the same argument to wp_list_comments to set the text as well. So, wp_list_comments(‘reply_text=whatever’); will do what you’re looking for.

      • Andy says:

        Hi, thanks for the quick response. I understand your explanation, but tried wp_list_comments(’reply_text=reply to this comment’); and it produced a syntax error? Can I access the get_comment_reply_link function to change the text it places into the comments and, if so, where? Thanks again for your patience.

        • Otto says:

          Well, that is actually the correct way to do it, so all I can say is that you messed up somewhere else. I just changed it on my own site’s theme here, as you can see. It now says “Reply to this Comment” instead of just reply.

          You can also do it via the array method, which I personally find to be cleaner looking. Here’s an example of that which changes the reply text and the avatar size as well:


          wp_list_comments(array(
          'avatar_size'=>48,
          'reply_text'=>'Reply to this Comment'
          ));

  52. Pingback: WordPress 2.7 Comment Template | Pinoy Teens

  53. David Cheong says:

    Thanks for the guide. Now we can get ready for new themes to be compatible and usable for 2.7 version which is going to be release soon. :)

  54. Pingback: Tips on How to get ready for WordPress 2.7 | Earning Money Online Guide and Tips - davcheong - Blog Tips Help On How I Make Money Online ::

  55. Well, I know what I’m going to be doing this weekend! Good post, very useful, thanks.

  56. Pingback: WordPress 2.7: Personnaliser l’affichage des commentaires - Emmanuel GEORJON

  57. Pingback: WordPress 2.7 beta 2 i garść ciekawych artykułów | WPNinja

  58. Pingback: digitalrendezvous | blog - Crazy Horse

  59. Pingback: AJAX commenting in WordPress 2.7 | LimeTouch

  60. Hi!

    I’m probably going to wait for proper release before moving to 2.7, as it isn’t far off.

    This functionality should hopefully massively streamline my maintanence work – at the moment I’m using a plugin to achieve threaded comments, but if the plugin uses compatible headings, I don’t foresee there being major problems with changing things across, and using WordPress Native features.

    However, I have QUESTIONS! Is there going to be native support for having:
    a) E-Mail notification for a commenter when someone replies to their comment?
    b) E-Mail notification for an author when one of their posts specifically is commented on?

    I’ve not been able to find settings for these in my current WordPress version (I’m only on 2.6)

    • Otto says:

      a) No. However, it does have hooks in the right spots to do that sort of thing, so it is possible to write simple plugins which adds that.

      b) Yes. WordPress 2.7 has a function that notifies the post author of a new comment on their posts, after it has been approved by a moderator (if moderation is enabled).

  61. Pingback: WordPress 2.7 Threaded Comments

  62. fer says:

    Fine! As I installed wordpress 2.7 turn me down here to put all this into practice … Greetings!

  63. Pingback: WordPress Wednesday News: WordPress 2.7 Beta 2, Danger WordPress Faker, and More WordCamps | The Blog Herald

  64. Prasannah says:

    Thanks for the extensive article Otto! I’m modifying a theme on my own.

    Currently, under , I am displaying a alert for moderation to be approved using if ( $comment->comment_approved == '0' ).

    What is the new function to check this?

    • Otto says:

      I’m not sure what exactly you mean here, but the wp_list_comments function displays unapproved comments to the person who writes them, along with the text “Your comment is awaiting moderation”.

  65. ChaosKaizer says:

    awesome, i just upgrade and I’m kind of dislike the reply_links (onclick==obtrusive) and also the comment-reply form behaviour is hard to control and break my theme so I’d to created my own reply_links with thickbox (graybox form). you can check the demo at my blog (running on 2.7b2).

  66. fatihturan says:

    Hello.

    I’m editing my blog theme for new WordPress 2.7 version. However i want to add new “Comment Reply” functionality to my blog theme. But there is a problem. I can’t get comment reply link on comments.

    I created two comments template for old WordPress 2.6.3 and new WordPress 2.7. New comments template (comments.php)’s code is here: http://pastebin.com/m264c16fd

    Also i’m using custom comment styling in functions.php (throught new wp_list_comments‘s callback argument). Codes is here: http://pastebin.com/m43b50f3e

    So how i can add custom reply link to my comments? I can’t. :)

    Sorry for bad English.

    • Otto says:

      There’s few other problems with your callback (mainly that it doesn’t do threading properly), but if we ignore that, then all you need to add is something like this:

      <div class="reply">
      <?php comment_reply_link(); ?>
      </div>

  67. BoltClock says:

    I’m very worried that I’ll lose control over the HTML produced by WordPress if I use wp_list_comments() in my theme. Are there individual functions that handle all the new commenting features and I could use to keep control over my comments HTML?

    • Otto says:

      There’s two ways to respond to this, so I’ll cover them both.

      1. Why would you really need to retain that much control over the html for the specific case of comments? What exactly is in the html of a comment that you would want to edit anyway? All comments are basically the same, there’s an avatar (maybe), the user information (name, url, etc), perhaps the time or age of the comment, and then the comment itself. These are usually organized into specific divs with specific classes and such, for styling. What would you add or subtract to this basic layout? Remember, XHTML is supposed to be semantic markup. If you want to change the look of the thing, then you’re not supposed to alter the XHTML itself. That’s what the CSS is for. The XHTML is only there to define the actual elements of data, not to define a layout. The wp_list_comments function outputs either a UL/LI set of comments or a DIV nested set, and those should suffice for all realistic situations. Individual bits are controllable, but there should never really be a need to change the underlying layout.

      2. Still, if you really, really need total control, then look closer at the ‘callback’ argument. It’s in the Walker_Comment class, and it gets passed in from wp_list_comments. Basically, you can make a function to display a comment however you see fit, then call the wp_list_comments function, and pass the name of your own function as the callback argument, thus giving you total control over the comment’s XHTML.

      • BoltClock says:

        Hmmm I see entirely your point in #1 now, oops :S I’ll see if I can handle it with CSS alone first then. But thanks for clarifying it anyway, I’ll take note of that.

  68. Pingback: WordPress 2.7 Updates | Mamma Mac.com

  69. Matt Dinnery says:

    Hiya – would anybody mind taking a look at http://www.medicaladmissions.co.uk/blog/ and telling me why the “Leave a reply” doesn’t change to “Leave a reply to ???” when I click on one of the comment ‘Reply’ buttons?

    I’ve added the code bit-by-bit as defined above, and it did work, right up until I added whatever bit makes the reply form move itself to the comment box – then it just says “Leave a reply” again!

    Thanks in advance.

    • Otto says:

      I probably should clarify that a little bit. That option only works when javascript is disabled. In that case, the page gets reloaded with the users name and focused on the comment form. With javascript enabled, the comment form moves up instantly and the name does not appear or change.

      Disable javascript in your browser then try to reply to somebody. See what happens.

  70. Chris says:

    Help Please! I had someone make my theme for me and I can’t get in contact with them anymore, I don’t know what to do with my comment.php =[ Here it is:
    _____________________________________________________________________
    (Basic comments.php file removed by Otto)
    _____________________________________________________________________

    If you could update it for me that would be awesome! I could like pay! Thanks

    • Otto says:

      That comments.php file is pretty basic, you could probably simply replace it with the one from the default theme and it would work fine.

      That said, there’s nothing you really NEED to do. Old comments.php files will still work just fine with WordPress 2.7, you just won’t get the threading and paging features until you modify it.

  71. Pingback: WordPress Wednesday News: 2.7 Delayed, Sneak Peak Video, Help WordPress iPhone, WordCamps | The Blog Herald

  72. Pingback: Clifton Griffin | Upgrading to Wordpress 2.7 beta 3 |

  73. Jim says:

    Has anyone documented the parameters taken by wp_list_comments() other than avatar size and reply text that you mentioned in the comments? I am particularly interested in changing the “[post author] says:” before the comment itself.

  74. Pingback: Wordpress 2.7 Comment Threading | Jeremy Clark - A Tech Blog -

  75. Antti says:

    And how about date format? I don’t find any way to chance that default “November 18th, 2008 at 6:31 am” – where does it comes from anyway?

    • Otto says:

      You can put a filter function on ‘get_comment_date’ and ‘get_comment_time’ to change the look of those two pieces.


      function change_comment_date($datestring, $dateformat) {
      global $comment;
      return mysql2date('YOUR_DATE_FORMAT_HERE', $comment->comment_date);
      }
      add_filter('get_comment_date','change_comment_date',10,2);

      The get_comment_time filter function also receives a third parameter of whether or not the time should be returned in GMT.

      The “at” piece is currently not editable, except for with the multi-lingual translation system. Here’s the thing, because the wp_list_comments is relatively new, it’s not entirely 100% configurable yet. In time, it will become more so, as work on 2.8 progresses. Some of the 2.7 point releases will probably add enhancements in this regard. Nevertheless, it is a work in progress.

  76. Pingback: WordPress Wednesday News: Beta 3 Released, WordCamp Australia, No WordPress 2.6.4, and More | The Blog Herald

  77. Chris says:

    The first part of the post is great until you get to the Javascript part and you get very vague after you mention adding a line to the header.

    Why not show the comments.php with the changes to allow the javascript feature? I think most looking at this post were looking on updating for the new features not being half-working.

    • Otto says:

      There’s really not a whole lot to the javascript functionality. All you have to do is to add that line to the header and then to make sure that the ID of the form is pretty much as I describe it. That’s it, nothing more to it. What the javascript code does is to a) make the “reply to this comment” pieces appear and b) make the comment form move up to those when you click on them. Try it out here: pick a comment, click the reply link underneath it.

      Here’s a link to a complete example comments.php file: http://ottodestruct.com/comments.phps

      That is the actual comments.php I’m using on this site. I modified it as I was writing this article, pretty much, and all I really did was to detail the changes as I made them. Honestly, that file is not all that different from the ones that come with the 2.7 default theme. It’s easier to modify the file than it seems. :)

  78. Matt Dinnery says:

    Hi Otto (& all),
    Just to say, when using the “new” comments code with 2.7b3 that autogenerated avatars do not work.

    It’s been fixed now, you just need to get a ‘nightly build’ from the WP site and its all good.

    2.7b1 and 2.7b2 are unaffected!

  79. Pingback: Dig Gadgets » Blog Archive » Starting up a fresh blog

  80. manu says:

    And how to collapse the threaded comments, to hide(-) or show (+)???

  81. manu says:

    Hi,

    How could I get the comment count to count only comments and no replys?

    thanks in advance.

  82. Pingback: WordPress News: WordPress 2.7 New Login, WordCamp Australia, WordPress 2.6.5 Security Update, BuddyPress, and More | The Blog Herald

  83. Dan Lee says:

    Can someone give me a hand here? This might simple CSS, but I’d like to throw out a scenario that would really help me out if I fully understood it. When viewing the source of the comments with the new 2.7 comments.php file I’m seeing this as an li class:

    class=”comment byuser comment-author-admin bypostauthor odd alt thread-odd thread-alt depth-1″

    That’s a big class, or lots of classes, but help me out here. Lets say I want to make every admin’s comment to be the color red. In css, can I simply do this?

    li.comment-author-admin {color: red;}

    I can’t, because I’ve tried that. So how do I go about making good use of all of these classes?

  84. Dan Lee says:

    Bleh, it does do that. My apologies. Thanks for this great article. I tweeted it. This is the best resource I’ve found regarding wp_list_comments() in 2.7 thus far. Keep on replying!

  85. baal666 says:

    Hi Otto.

    Thanks for that great page.

    Only 2 questions:

    1) I’ve tried the function

    function change_comment_date($datestring, $dateformat) {
    global $comment;
    return mysql2date(‘j F Y’, $comment->comment_date);
    }
    add_filter(‘get_comment_date’,'change_comment_date’);

    to change the look of the date and did put it in functions.php but I got the following error:

    Warning: Missing argument 2 for change_comment_date() in /home/…./functions.php on line 7
    (Line 7 is <?php function change_comment_date($datestring, $dateformat) { )

    2) Is it possible to customize the text? I’d like to replace that “Says” by something else.

    Thanks a lot and keep up the good work!

    • bob says:

      Yes, i too am wondering how to change the “Says” text and also the text link for threaded replies (“Reply to this Comment” on this blog here). Also what about the placement of this new Reply link?

    • Otto says:

      1. Use add_filter(’get_comment_date’,’change_comment_date’,10,2); instead. You have to specify that it gets 2 parameters. My bad.

      2. The only way to change “Says” currently is to create a callback function that outputs a single comment and pass that into the wp_list_comments as the “callback” parameter. I went into this above a bit. This is, of course, a lot of effort to go to for one word, so I suggest just living with it for now.

      However, if you want to do it with CSS, then you can hide the “Says” entirely, as it is in a span with the class of “says”. You could replace it with :after and such like that as well, but it wouldn’t work in IE.

  86. Pingback: WordPress 2.7 RC1: A closer look « Systematic Abstraction

  87. Pingback: Q/A: How can I add threaded comments to WordPress 2.7? › Brolly

  88. Pingback: Quick WordPress 2.7 Thoughts | Sherwinpedia

  89. DjFlush says:

    Excellent, testing this out.

  90. Chaivoot says:

    2 days ago I registered new wordpress blog at wordpress.com
    I’ve seen the difference backoffice interface of my wordpress 2.6.5

    Is that interface of version 2.7?

  91. Pingback: All you wanted to know about WordPress 2.7 | Featured articles | WereWP

  92. Pingback: New Features In WordPress 2.7

  93. Pingback: Top WordPress 2.7 Tips, Hacks, Plugins & Resources | ShanKri-la

  94. Pingback: Top WordPress 2.7 Tips, Hacks, Plugins & Resources | ShanKri-la

  95. Pingback: Top WordPress 2.7 Tips, Hacks, Plugins & Resources | ShanKri-la

  96. Jauhari says:

    It’s possible to separate count on comment and trackback? How to use that?

    • John Doe says:

      Testing a reply to a comment

    • Otto says:

      If you call the comments_template function like this:

      comments_template(‘/comments.php’, true);

      Then it pre-separates the comments into trackbacks and such, and creates a special place to hold them in the $wp_query object. You can then count them by doing this:

      global $wp_query;
      echo count($wp_query->comments_by_type['pings']); // this is both pingbacks and trackbacks
      echo count($wp_query->comments_by_type['trackback']);
      echo count($wp_query->comments_by_type['pingback']);
      echo count($wp_query->comments_by_type['comments']);

      Like that.

  97. Pingback: Wordpress 2.7 ve yeni yorum alanını entegre etmek | Teknoloji Herşeyim

  98. Mike says:

    Otto, great post. Since 2.7 came out yesterday I’ve been banging my head against the wall, trying to get a handle on the changes, and this article helps, a huge amount.

    I’ve tried a few other things, and managed to get comments working, and stylized, but not exactly how I want.

    Do you have an example of the CSS you’re using, that works with the code you’ve put together, to work off of? I’m confused as to what the output of your code does, that’s different from what I’ve got already.

    Thanks again.

    • Otto says:

      I’m really not using a whole heck of a lot of comment styling on this site. I put a couple of background colors on the .bypostauthor and .pingback and .trackback classes, and a few margins here and there, but for the most part this is the basic comments layout with no frills.

      Try posting your site URL over on the wordpress.org forums, many of those people are good with styling.

  99. Saberj says:

    Otto: Could you take a look at my post WordPress Support Forums and let me know if there is a way to control all of the comment’s text itself. As I can see, the only way to do so is by styling the p tags. And with the way the theme I’m using works, it wants to make each p into its own comment box.

    From what I can tell there is no div/span tag to just get a grasp on the text itself of the comment, whereas the date/avatar information each has their own easily styled div tags. Any help would be much appreciated.

  100. Pingback: daburnas Logbuch » Blog Archi » Intern: Update auf Wordpress 2.7

  101. Thank you. I got the threaded comments to work. Excellent job in posting this very helpful article.

  102. Pingback: Update auf WordPress 2.7 - Dodge this!

  103. Pingback: WordPress 2.7 and Threaded Comments » Solo Technology

  104. Pingback: WordPress 2.7 Commenti Nidificati e Paginati » Archivi Blog » WordPress Italy

  105. Charles says:

    I noticed that when you hit reply it opens the comment form right below the post your are replying to. I do not think this is the default behavior, how did you accomplish this?

  106. James says:

    Fantastic release, I’ve just started upgrading my blogs to use it. Nice clean and easy to use interface.

  107. jeremy says:

    Great article!

    I was stuck for most of two days, though, even though i was doing everything 100% exactly precisely as you laid it out… until i realized that threaded comments seems to be OFF by default. D’oh!

  108. Pingback: Tech Projects » Wordpress 2.7 Upgrade

  109. Paolo says:

    Hi Otto!

    Unfortunatly the line

    add_filter(‘comments_template’, ‘legacy_comments’);

    in functions.php produces this error:

    Warning: Cannot modify header information – headers already sent by (output started at D:\serverweb\qumranblog\wp-content\themes\parrocchialagaccio\functions.php:8) in D:\serverweb\qumranblog\wp-includes\pluggable.php on line 850

    Any idea how to resolve it?

    • Otto says:

      You have some blank lines or something at the end of your functions.php file. According to that error message, line 8 produces output.

  110. Pingback: jaf.eng.br » Blog Archive » Comentários no Wordpress 2.7

  111. Pingback: WordPress 2.7 Comments | NSLog();

  112. Pingback: Mastering Your WordPress 2.7 Theme & Admin Area: Tips and Tricks

  113. Pingback: Mastering Your WordPress 2.7 Theme & Admin Area: Tips and Tricks

  114. Pingback: Mastering Your WordPress 2.7 Theme & Admin Area: Tips and Tricks

  115. Pingback: Neufeld Computer Services | Wordpress 2.7 and Themes

  116. Pingback: Hello WordPress 2.7!

  117. Pingback: Actualizar Theme a WordPress 2.7: Comentarios con replicas o hilos | [ Neuronal Training ]:

  118. nice post… very helpfull

  119. Sakib says:

    how you colorize your comments? can you please tell me any easier hacks and thus I can input to my site. thanks again.

    • Otto says:

      Styling them is easy and I explain some of the built in classes that get added above. It’s really just a matter of adding styles to your theme’s style.css file. For example, to make my own comments blue here, I use this in my stylesheet:

      li.bypostauthor { background-color: #87cefa; }

      Easy.

  120. Hey! Great tutorial. Just FYI, you have a slight code error in your http://ottodestruct.com/comments.phps file.

    The code at present for the last 5 lines is as such:

    <?php
    endif;

    endif;

    It should read:

    I know this is small but will result in validation errors and layout glitches. Thanks for the script!

    • Otto says:

      Actually, no, those two lines are correct and supposed to be there for my case. The corresponding “if” statements that they are ending are:
      if ('open' == $post-> comment_status) :
      and
      if ( get_option('comment_registration') && !$user_ID )

      • Sorry about the last comment. It didn’t come through correctly at all…

        The problem isn’t with the statements. its with the closing tags. The problem is that you put the last closing at the END of the file. It needs to be in the middle of the last two statements.

        Otherwise the does not correctly close out in certain situations. Nest your code and you’ll see what I mean…

      • Okay so apparently I don’t know what I’m doing at all by putting the code tags in this site cause every time I do nothing comes up…

        I’ll try again. Basically the last closing div in your script needs to be in between the two endif statements. Otherwise validation errors are caused and the div id=response element is not closed out correctly in some situation.

        • Otto says:

          Ahh, I see what you’re getting at. Yes, that would be invalid, but only if I required comment_registration.

          Also, don’t use code tags to surround html code. Use pre tags. Code tags just make text fixed width, pre tags prevent html processing as well.

  121. Pingback: What’s new in WordPress 2.7 | matthalliday.ca

  122. Pingback: WordPress 2.7 Enable Threaded Comments | Gary Jones

  123. Zofren says:

    I followed your instructions but I still have old fashioned not-threaded no-reply comments. I don’t know where I missed something.

    To start, I took the kubrick theme’s comments.php as a work-basis. I just translated it. And I add the little line in the header.php.

    It still doesn’t work !

  124. Pingback: WordPress 2.7 Comment Threading Howto » will.ph

  125. Darran says:

    Nice write up and thanks to it, I have just updated my theme for comment threading and paging in AJAX.

    http://limetouch.com/archives/13-test-drive/

  126. Mike says:

    Is there a way to restrict who can reply? Say I want to allow registered users to reply to the post or to comments made by the post author – but not to comments made by other registered users. Would also need to allow the post author to reply to anything. I know, it’s a stretch.

  127. Mike says:

    another thing for the wish list – an additional class added to a comment based on the type of wp registration such that we can style differently for administrators, authors, users, etc.

  128. Thank you for taking the time to explain this new fuctionality.
    What I see is, that the powerful function.php is getting used.

    Thank you,

  129. Pingback: Aktivasi Threaded Comment di WordPress 2.7 | .: Blaszta! :.

  130. Jim says:

    Thanks for the help. Now i added new comment support on my themes. And its working perfectly. Thanks again..:)

  131. TheMystical says:

    2.7 is awesome, if I understand correctly is gonna be easier to have different styles for comments posted by admin, authors, guest etc. right? If so is there a list of classes to look at or we can define them ourselves, or both?

    • xdesi says:

      It is easier, and you can do both I think.

      The whole of the last section, under “Styling” covers exactly this.

  132. jim says:

    Thank you very much for this tutorial, I was able to update my theme thanks to your help!

  133. Pingback: Wordpress 2.7: Reageren op reacties | Weblog van Niek ten Hoopen

  134. jhay says:

    How I go about inserting this code:

    if ( is_singular() ) wp_enqueue_script( 'comment-reply' );

    in my theme’s header.php file?

  135. Sean says:

    Nice article, thanks. Any idea what’s going on with the comments_popup link? It doesn’t work anymore after upgrading from 2.2 to 2.7. Not just with my theme, but even the default Kubrick theme. Pressing the popup brings up a window that just loads the permalink to the specific post. Anybody figured this out, and how to fix it yet? Or is this a bug?

  136. eyn says:

    I was having trouble getting the move comment form via Javascript to work and it turns out to be a problem related to HTML markup. You did mention about some of the requirements such as the required “respond” id but you forgot to add in some extra information about other markups that is used by the script, namely “div-comment-id”. I didn’t have a div container with that ID due to custom comment callback and it is causing the script to fail without giving any errors. By going through the JS source I am able to find out that div-comment-ID is part of the requirement for things to work. Without this div container the script will return prematurely without giving any errors, making it really hard to debug.

    To get the div container with comment id, one would add the following to their markup:

    <div id="div-comment-<?php comment_ID(); ?>">

    I suggest you put a section in your article listing all markup used by the Javascript as it will be helpful for other developers that opted for custom callback for comment listing.

    Other than that, thanks for writing such informative article. The problem I mentioned is the only one that is causing me headaches while following your article.

  137. Pingback: Mastering Your WordPress 2.7 Theme & Admin Area: Tips and Tricks on LinkArchive

  138. Pingback: Mastering Your WordPress 2.7 Theme & Admin Area: Tips and Tricks on LinkArchive

  139. Pingback: Mastering Your WordPress 2.7 Theme & Admin Area: Tips and Tricks on LinkArchive

  140. Adriana says:

    Thanks for the tutorial. I seem to be hitting a snag and if you have any idea (although I certainly do not expect it), I would be grateful. I have inserted/replace all the necessary code and the comment box “moves” correctly if I hit ‘reply’ to a comment. However, there is no Cancel link showing up.

  141. Pingback: Paginated comments with WordPress 2.7 and the Copyblogger theme | Christian Schenk

  142. calvin says:

    hi im not good with javascript and i was wondering if you could help me use the style from my old 2.6 site.

    basically, it would be (author), on (date) said:

    (comment goes here)

    author should be bold and not italicized (unlike the default one).

    really would appreciate any help. thanks! kudos for the great work you’ve done with threaded comments btw.

  143. Pingback: Upgrade auf WordPress 2.7 - rattlab.net

  144. Pingback: Mastering Your WordPress 2.7 Theme & Admin Area: Tips and Tricks | Web Hosting and Domains

  145. Pingback: Mastering Your WordPress 2.7 Theme & Admin Area: Tips and Tricks | Web Hosting and Domains

  146. Pingback: Mastering Your WordPress 2.7 Theme & Admin Area: Tips and Tricks | Web Hosting and Domains

  147. Meaw says:

    Thanks, it’s useful for me.
    OK bye :)

  148. Ron says:

    What happens with the MicroID for unverified users(commenters)? Section 5 of the MicroID spec says, “An Issuer MUST NOT generate a MicroID until it has verified that the Individual or Service Provider has control over a given EntityURI. Methods for such verification are out of scope for this specification and may vary according to local service policies and the URI scheme in question.” and it looks like this generates a MicroID for all comments. It appears that generating them for verified WP Users or OpenIDs would be ok, but generating them for anonymous, ie, unverfied users is not.

    • Otto says:

      That really doesn’t make any sense, because it makes MicroID’s more than a little pointless. But then again, the MicroID spec keeps changing anyway. I mean, it also says that a MicroID must be created by an Issuer, not an individual, and yet they have a generator on their own page: http://microid.org/ . Anyway, I’m not an “issuer”.

      MicroID has many possible purposes. If you know my email address and, say, my Digg profile page (back when Digg had MicroIDs on them), then you can verify that that is my account by computing the MicroID with that Profile URL and my email address and comparing the two.

      With the MicroID in a comment like this, you can verify what email address somebody used, in order to see if it’s the correct one for the given URL. Like if somebody put in a URL they don’t control, and a fake email address, then the MicroIDs would not match, and so it’s provably not from that person. On the other hand, this use of the MicroID does not verify authorship, since, like you say, you can use any email address. It’s just a simple way to disprove false authorship.

      • Ron says:

        I’m having trouble understanding that. Unless you verify control over the email address (the resource) that you’re computing a MicroID for, then this doesn’t seem prove or disprove anything other than it’s possible for anyone to put anyone’s email address into a comment and have a MicroID computed for it. It wouldn’t prove or disprove that the persons to whom that address and URL belongs had anything to do with the comment left behind somewhere. Rather than verified addresses making MicroID pointless, it seems they’re pointless without them.

        In the example you cite above, it would indeed prove that that is your Digg account, but only because the email address is known to have been verified by Digg when you created your Digg account. You clicked on the confirmation link, which validated your e-mail address. Any assertion based on that address associated with Digg is of a validated address. Someone who had control over that address opened that Digg account. If there were a MicroID on my comment here, it would it would only prove that if you run the same email address and the same URL through the same formula, that you’re going to get the same result every time. You’ve gained nothing over just having had my email and URL to begin with.

        But with all this having now been said, I don’t see a MicroID on my previous comment here, which suggests that you’re not issuing them for unverified users after all. I do see one on yours.

        Yours: <li class=”comment byuser comment-author-otto bypostauthor even depth-2 microid-mailto+http:sha1:23e9670868f6d2b16fe1f6b3db80c8f0423a082a” id=”comment-6619″>

        Mine: <li class=”comment odd alt thread-odd thread-alt depth-1 parent” id=”comment-6617″>

        I guess I have my answer now.

        So… anyway, I also want to thank you for explaining the enhancements in 2.7 as I’m trying to bring the old Benevolence theme forward.

        • Otto says:

          No Ron, you didn’t get a MicroID because you didn’t put in a URL for me to calculate one with. I am giving MicroID’s to every commenter here, or rather, computing the MicroID based on their own inputs.

          And it doesn’t *prove* anything, it *disproves* something.

          Let’s say somebody comes here and puts in your URL and name and some fake email address (perhaps because they don’t know yours). With the MicroID, you can see that, without seeing their email address, and prove that it wasn’t your email address used to make that comment. In other words, it lets you falsify the anonymous comment, if you know the email address of the real person who controls that URL.

          You’re correct, it proves nothing, but it can disprove a false comment if the commenter didn’t use the correct information.

          • Ron says:

            Ah yes. (I didn’t leave a URL). Not with you on there being any ability to disprove without anything proven to base it off of though. I can leave a comment somewhere with your email and your Digg URL, and if it generates a MicroID, it’s going to match, thus seemingly proving that you did leave the comment, since no effort was made to validate control. You can assert that you didn’t leave the comment, but there’s nothing of value upon which you can stake that claim.

            At the same time, I could leave a comment with valid information and disown it when in fact I made it, because again, there’s been no effort to validate the resource. Such MicroIDs have no credibility upon which they can disprove anything.

            If this is how MicroID is supposed to work, it’s completely worthless.

          • Otto says:

            No, you’re still missing the point. If you use my email and URL on some other site, then it doesn’t *prove* anything at all, whether MicroIDs are there or not. However, if you use my URL but some fake email, then that means that I can easily *disprove* that it was me. Get it? A legit MicroID proves nothing, because anybody can generate it, but an illegitimate one can disprove a thing.

            That’s how MicroID works for the unauthenticated side of things. But it does have other uses, of course, mostly like you claim, for cases where the email is verified. However, that’s of little or no use to blogs..

            The main reason I want them tied to comments is for search reasons. If there was a MicroID search engine, then every comment I leave on sites could be found by searching for that MicroID. I could tie my online activity together that way.

  149. John Turner says:

    Awesome tutorial!

  150. Tracy says:

    Cool info on the comments file. Does this apply to the latest release of wordpress 2.7 too? Are there any other changes made since.

  151. Great explanation! Thanks a bunch.

  152. Pingback: CoffeeBear.net » Blog Archive » Updating VectorLover Theme

  153. Pingback: Meli Melo’S Blog » Deux Nouveaux thèmes

  154. Meli Melo says:

    Thank you very much for those explanations and the file which works very well !

  155. Pingback: Hacks to boost your WordPress 2.7 blog

  156. Pingback: Wordpress 2.7 is gold! | flyingkiwis design

  157. Pingback: Lo hice y lo entendí | Comentarios anidados con WordPress 2.7, nueva vista para archivos y otros cambios en la plantilla

  158. Pingback: Typograph Theme Update - Now With Threaded Comments | Design is Philosophy - The Pink &amp Yellow Media Blog

  159. Eivind M. says:

    Thanks, this worked great!! :D

  160. Pingback: Make Old Themes Compatible With Wordpress 2.7 Comment Features | eJabs

  161. Pingback: scriptygoddess » Wordpress wp_list_comments()

  162. Pingback: AMB Album » Mastering Your WordPress 2.7 Theme & Admin Area: Tips and Tricks

  163. Pingback: AMB Album » Mastering Your WordPress 2.7 Theme & Admin Area: Tips and Tricks

  164. Pingback: AMB Album » Mastering Your WordPress 2.7 Theme & Admin Area: Tips and Tricks

  165. Kristan says:

    To be honest, it WAS much simpler to take your code and copy & paste it in. :P But thank you SO MUCH for this tutorial. I did START just following along… ;P

    (Btw, it might be more clear to provided the entire “< ?php…” part in that header “if_singular” line b/c I’m a dummy and just put that line in by itself, so it printed at the top of my site!)

    Thank you thank you thank you!

  166. Kristan says:

    Wait… is it just me or do authors whose comments are replied to NOT receive email replies? Isn’t that the whole point??

  167. Pingback: Security and Hacking: The State of WordPress Blogs | The Blog Herald

  168. Sanjay M says:

    Thanks a ton I finally did it after a lot of struggle thanks to your site! Could u pls provide some info on how to get the indentation and shading of the nested comments… also wondering if there’s any way we could add a subject to the first comment.

  169. John Turner says:

    Awesome Tutorial… just used it to build me new theme

  170. Matt Algren says:

    Thanks for the tutorial, especially with all the ajax-ifying. I’m so close I can taste it, but I have a question about styling. I set my css to give post author comments a different background and now any comment that replies to mine inherits my background. I notice that you aren’t having that problem, but I can’t figure out why!

    Best example here. Wendy’s reply at 12:39pm should revert to the original background color, but instead it’s kept mine.

    If it helps, I totally stole the comments section of the default theme. My css here.

    Help?

    • Otto says:

      The basic problem is that you’re not resetting the background color. Children inherit traits from their parents. In your case, the comment below yours is inheriting the .bypostauthor traits.

      You may want to set a background-color default, to something like “li.bypostauthor li”, in order to reset the background color.

      • Matt Algren says:

        That did it! I had to specify a little more because of the alternating color, but once I did that for “.thread-alt li.bypostauthor li” AND “.thread-even li.bypostauthor li” everything fell into place.

        Thanks a bunch!

        • Otto says:

          Instead of using alt and even, I’d say to use odd and even. The alt is the same as odd, currently, but with various page and comment numbering settings, that could change. Whereas odd and even will always alternate between each other.

    • Rudi says:

      Page comment will cause duplicate meta data detected by google, but I have to use it for some reasons.

  171. Hi Otto,

    Just a quick note to add, if you can stand some shameless plugin plugging…

    If you’d like to display a number along each comment, to help readers identify at a glance which way the discussion is going, a new plugin can provide accurate numbering regardless of whether you’re displaying comments in ascending or descending date order, with or without paging, and with or without threading:

    Greg’s Threaded Comment Numbering

    All the best,
    Greg

  172. El Bucanero says:

    Thanks a lot for this great tutorial!

    I’ve successfully edited the WP theme I was using to support the new 2.7+ comment features! :)

    regards from Argentina!
    Buk

  173. Vaibhav says:

    Dude, you are a lie saver. I was afraid I am gonna have to dig through the documentation to get my theme up to date.

    Kudos.

  174. Lisandro Vico says:

    Hi Otto. First of all I have to say this tutorial save my life. Just use your code, tweaked it a little bit and works grate.

    However, I’m having a little problem. You can see it Here: http://img24.imageshack.us/img24/9431/picture1nd6.png

    What happens is that when I try to respond to the last comment, the reply doesn’t nest!…I can reply all comments before the last one… don’t know what I’m doing wrong.

    Checked and ReChecked the code, but can’t find the answer. Do you have any idea what can it be? I’m sure missing something.

  175. Pingback: 2009 Redesign | Sea Slugs! Anime Blog

  176. Ben K. says:

    Otto: Thanks for this tutorial. It’s really helpful.

    I have one question that I was hoping you would be able to answer. I’ve got threading up and running, but I’m running up against a problem with the final level of nesting. There’s no sign of the “Comments won’t nest below this level” language or the “Reply here” link that should drop a comment in at the same level but below the most recent one. Example is here: http://test.secondavenuesagas.com/2007/11/15/new-aside-post-on-top/comment-page-1/#comment-30

    Anything you know about working around that problem?

    • Otto says:

      I’m not sure what you mean, exactly. There is no “comments won’t nest” language at the last level. The only difference on the bottom level is that the Reply link stops showing up. That’s it. Nothing more happens.

      If somebody wants to respond on the same level as a comment, then they need to reply to the parent comment. Examine how the Digg commenting system works. Same principle.

    • Kai says:

      I’m wondering if there was ever a solution found for Ben’s questions re: adding “comments won’t nest below this level” text on the final comment allowed in a nested sequence.

      • Otto says:

        No, there isn’t. When the max depth is exceeded, get_comment_reply_link doesn’t return anything. You’d have to modify the get_comment_reply_link() function in comment-template.php.

  177. sam_m says:

    hi Otto,

    Good article. I’ve done what you explain for my WP2.7 comments but I have one problem. How can I stop the URL changing from:

    http://www.myblog.com/content/the-post-name

    to:

    http://www.myblog.com/content/the-post-name/comment-page-1#comment-305

    Everytime a new comment is added? This messes up my post page in the theme and requires the user to have to go back to the original post page. This did not happen prior to the upgrade to WP2.7

    Thx for any help you can give with this.

  178. sam_m says:

    I notice it does not happen on your blog.

    Your blog has

    http://www.myblog.com/content/the-post-name/#comment-305

    instead of

    http://www.myblog.com/content/the-post-name/comment-page-1#comment-305

    So, I have this extra >>> comment-page-1#

    Thx for any help.

    • Otto says:

      The “comment-page-1″ is the result of enabling comment paging. If you were to go to an earlier page of comments on my site (click the Older Comments link), then you’d see that as well. That’s not a bug, that’s how it goes between pages.

      If you don’t want paging, turn it off.

      • sam_m says:

        Hi Otto,

        Thx for the reply

        I did do as you said, now I have the URL, similar to yours i.e.

        http://www.myblog.com/content/#comment-305

        But the problem still is there. I get this page which is not the full post – only the title, odd side bar and the comments for the article, including the new one added.

        Any ideas why this is happening?

        • sam_m says:

          I tried it with the default WordPress 2.7 theme, it happens in the default theme too! So, now I’m confused. Is this a WordPress 2.7 problem? Should I re-upgrade?

          • sam_m says:

            Hi Otto,

            Found out the problem – It was the Search Unleashed plugin. So, not the theme or config of WordPress 2.7!

            Thx for your help.

  179. Pingback: Seitentemplate Gästebuch mit umgekehrter Reihenfolge | im-Tal.net

  180. Pingback: Addressing those who comment: The wrong ways » Blogussion

  181. Scott says:

    Just testing out the comment functionality. Great Post!

  182. Pingback: cdharrison.com » archive » Wordpress 2.7 Comments Not Threading

  183. Otto, you are the man and the only reason I ever got this whole system to work in the first place. That being said, I just autoupgraded to 2.7.1 and now my comments no longer honor the pagination breaks. The older comments have the “older comments” link but the newer ones are well over the 30 comment break and they are not paginating. Any ideas why upgrading to 2.7.1 might change the behavior?

    When you specify a break for paginating… does it count only first level comments or all comments regardless of level?

    • Otto says:

      Only top level comments count for pagination. And a few bugs regarding this were fixed in 2.7.1, so yes, you may notice the behavior changes somewhat.

  184. Pingback: Brève Wordpress: 40 liens, thèmes, plugins et astuces en tout genre !

  185. missmaddis says:

    Hi. All I want to be able to do is using the function “reply” in comments and get the threaded comments capability but i dont know how to, and this is all greek to me.. someone please help me?

  186. Adi Popescu says:

    I’ve activated the threaded comments but i want to change the text “Reply to this comment” where do i have to go in my ftp ?

  187. Johnny C says:

    hey man! maybe you could gimme a hand! is there anyway to mess around with comments layout? on the older “foreach”, it was easy. if you check out this link -> http://migre.me/2Ed <- you’ll see a couple comments, already using the wp_list_comments() and nesting working. BUT… you can see, for example, the number 2. completely out of place. Messing around with firebug I found out that a div style=”clear:both;” would do the trick… but I have no idea where to do it!

    • Otto says:

      Why not find the appropriate section to clear and then add the clear:both rule to your stylesheet instead? No need to add any HTML markup.

      Where at in the comments are you adding this div with a clear:both style, anyway?

  188. Pingback: Yoschis Blog » Grabbel Kiste #3

  189. Pingback: WordPress-Themes an V2.7 anpassen « Schöner “wohnen” im Web

  190. Zack says:

    Great tutorial, thanks a lot, I am going to modify my themes now.

  191. Tomas Sramek says:

    Finally all the info about comments in one place. Thanks!

  192. Johnny C says:

    I may have missed some part of it, but I’d like to know where I can edit the comment layout… like, I’m having some problems on some posts and comments. one example I have is this: http://www.proveisso.net/2008/08/filme-vegas

    the second comment is appearing on the side of my reply to the first comment, and not below. a simples div style=clear:both I guess could take care of it, but I don’t know where to put it =( any ideas?

  193. Pingback: 29 easy ways to fine tune your blog » malcolm coles

  194. Pingback: tekArtist » Lifestream for 2008-11-04

  195. Toto says:

    Thank you very much je te remercie du fond du coeur pour ce tutoriel !
    Bonne continuation, good luck ;)

  196. Pingback: In lieu of new content « Via Negativa

  197. Pingback: A Plugin for Unstyling Comment Replies | Darren Hoyt Dot Com

  198. brent says:

    I like the code generated by default by 2.7′s commenting system, with one exception. It adds ‘your comment is awaiting moderation’ in a bare tag, so if you want to style it you need to style all em tags in all comments, which I don’t want to do… Is there an easy way to just add a class to this one tag without re-writing the entire comment template from scratch?

    any help is GREATLY appreciated

    brent
    @
    mimoYmima.com

    • brent says:

      it stripped a little of my html in the comment above, I was trying to say it puts that moderation text in a bare -em- tag.

      brent
      @
      mimoymima.com

      • Otto says:

        Use CSS Selectors to only reference the direct descendant em tag, instead of all child em tags.

        Example:
        [div class=comment]
        [em] Awaiting moderation [/em]
        [p class=comment-text]
        Comment text here [em] Highlighted text [/em]
        [/p]
        [/div]

        CSS to reference the first em without touching the second one would look like this:

        .comment > em { color:red; }

        The greater than mark makes it only refer to direct children instead of all children. CSS Selectors are super-powerful, but very few people use them, for some reason.

        • brent says:

          I’ve used this before on stuff that enhanced the look of my page but not with things that were breaking the layout because I’m pretty sure it doesn’t work with ie6… I’ll have to run a test to be sure. The easier fix would be for the WP team to just throw a class on it. Seeing as some of the other divs in the comments code have something like 5 classes strung together I’d have thought this would have had at least one…

          brent
          @
          mimoymima.com

          • Otto says:

            Honestly, I’m dropping IE6 compatibility in my day-to-day work. With IE8 out already, and IE 7 having been around for yonks, there’s no reason to maintain compatibility with a browser that doesn’t even fully support CSS.

          • brent says:

            I wish I could just disregard it, unfortunately I think there are still a good amount of clueless people out there using it :( … it’s tempting though

          • brent says:

            I just noticed that your comments are showing up without me refreshing the page (I think) do you have a plugin to make that work or is that standard in wp2.7?

          • brent says:

            it might just be that I’m on such a slow connection at the moment that I forgot I refreshed :D

  199. hi otto,

    how do yo display alternating comments styling with this new tag?

    • Otto says:

      Just use the built in styles. Look above where I talk about odd, even, alt, and thread-odd, thread-even, and thread-alt. All you have to do is assign the styles you want to those classes in your CSS file.

    • never mind – i figured it out. wow, they really revamped this comments stuff in 2.7! it even applies a lot more css classes in the comments themselves – no additional foreach statements to style alternating comments. thanks anyway

  200. Pingback: Blog Redesign

  201. Ryan says:

    I have an issue with a theme that is really perplexing. In WP 2.7, the redirect_to URL from the “Login to reply” button and also the “You must be logged in to comment” end up 404′ing. If I add urlencode to the “You must be…” link, it works fine, but I shouldn’t need to do this. It doesn’t matter what permalinks are set to, it still 404′s. I’ve added FollowSymLinks to the htaccess and that didn’t solve it. The redirect_to URL is the full URL including the http://www... If I strip out the http://www.domain.com part it redirects to the login screen as it should. What would be causing this to happen? I’ve tried the disable canonical links plugin and no change.

  202. Dayna says:

    I’ve the div id=”div-comment-xxx”, got the JavaScript code in the head tag, reply link done as well, id=”respond” also there and the comment_id_field is there as well. But the form simply does not move up the page when I click on reply to comment. It just refreshes the page and the form stays at the bottom of the post.

    Any idea what could be wrong? I have tried to find the problem many times but couldn’t find out what’s wrong. :(

    Please help. Thanks :)

    • Otto says:

      Looking at the source of your site, it appears to me that you’ve customized your comment’s html using a callback (probably), and something is wrong with your call to comment_reply_link();

      That function call in your callback should look like this:
      comment_reply_link(array_merge( $args, array(‘add_below’ => ‘div-comment’, ‘depth’ => $depth, ‘max_depth’ => $args['max_depth'])))

      The “add_below” link is the important bit here.

      • Dayna says:

        Yup, I did used the callback function for my comments.

        You got it right. My ‘div-comment’ in this comment_reply_link was incorrect. I didn’t specify which div id.

        Thank you so much for your help. I have manage to get it working correctly on my site already. :)

  203. steve says:

    This was exactly what I needed to edit my theme for threaded comments, and stylized author comments. Thankyou, it was easy to read, and figure out, A++ for you my friend.

  204. Pingback: Wordpress 2.7 im November - Themes vorbereiten? | WEBSTYLE-BLOG.DE

  205. Laurens says:

    Hi,

    currently I’m working on some modifications on a blog. The blog is based on WP2.7 and has a custom theme, made by somebody else.
    Now I’m trying to get the threaded comments feature working, and I’ve used your tutorial but it isn’t working. I’ve added the line to the header.php file and the lines in the comments.php file, but it’s still not working.
    An example can be found here: http://www.software-innovators.nl/2009/03/29/het-nut-van-pauzes/
    Could you take a look at the source code of that page, please? Maybe you can find what is wrong with the structure or something? The blog’s content is Dutch, but the HTML page structure is English.

    Kind regards,

    • Otto says:

      Something is wrong with your reply links. It’s using the wrong kind of quotes. Instead of single quotes in the A link, it’s using double quotes, which it should not be doing.

      What does the actual PHP code in your comments.php look like? Post a copy on http://wordpress.pastebin.com and give me a link to it, so I can examine it.

  206. Pingback: Welcome to the Grid | 960bc

  207. Pablo Faria says:

    I coudn’t manage to make it work… I can’t get even a “reply” link for each comment. What could be wrong?

    • Marco says:

      Same here :( No “reply to comment” and no threading using your comments.php(s) :-(

      • Otto says:

        Are you sure that you enabled threaded comments in the admin screens? If it’s not turned on, then obviously you won’t see any changes.

        • Marco says:

          I have installed Brian’s Threaded Comments and replaced his comments.php with your file. THAT works. Very weird. WordPress’ threaded comments was already enabled. Weird weird. Thanks anyways.

  208. Pingback: Increase Comment Productivity on Your Blog

  209. Pingback: Interesting Articles #17 « DivitoDesign

  210. Pingback: WordPress 2.7 Threaded Comments Works In Thesis | GROWMAP.COM

  211. Dhini says:

    I use your comments.php but I don`t see a “Reply to this Comment” link for each comment. What could be wrong?

    • Otto says:

      Did you turn on threaded comments in the Settings->Discussion area?

      • Dhini says:

        What I must do in the Settings->Discussion area?

        thank you for reply my problem

        • Otto says:

          You’d have to turn on the threaded comments for there to be a reply link.

          • Dhini says:

            ?? Where can I have the threaded comments?
            From Cristina I know this link and If I follow your tutorial, dat would be the Reply to this Comment show.

            And I use comments.php, so I think more easer for me? But this Reply to this Comment not show

          • Otto says:

            I don’t understand your response.

            If you’ve made the changes to your theme as I describe in the article, and the Reply link doesn’t show, then you still need to enable the Threaded Comments option on the Settings->Discussion screen.

            The reply link will not show unless threaded comments are turned on.

            That’s all there is to it. I cannot explain it any better than that.

          • Dhini says:

            I see now the “Reply to this Comment” but when I click on it, the comment box does not open below like this

            Please help me?

          • Dhini says:

            It`s work Yay! Thank you :D
            but the comments form open little bit long and little bit difficult.
            Not direct open :(

            Would you help me please?

          • Otto says:

            Did you add the code to your theme’s header.php file, like I describe in the article above? Read the part about “The Power of Javascript” closer.

  212. Pingback: How to upgrade your theme to WordPress 2.7 › wp27 › Kaizeku Ban

  213. Loadfuel says:

    Thanks. I have been searching google for hours on how to style and enhance wordpress 2.7 comments.
    :)

  214. macus says:

    Hello & thanks for this great Post…! Just testing out the comment functionality.

  215. elana says:

    thx otto!
    this really helped in converting my old theme over to threaded comments! i was even able to style my author comments…

    one question which i don’t know if you can help with – i was displaying the commenters url after their name, like so:
    elana @ elanaspantry.com says:
    or
    heidi @ 101cookbooks.com says:
    before i implemented the new comment code

    was wondering where i would change that code now?

    here’s my code:
    if(get_comment_author_url())
    {
    echo '' . get_comment_author() . ' @ ' . get_comment_author_url_link() . '';
    }
    else { comment_author(); }

  216. Pam says:

    How do I style the comments? My old code was:

    commented on <a href="#comment-" title="">

    How do I implement that style to the new wp_list_comment thing?

  217. Pam says:

    My code did not show, wait here it is:

    commented on <a href=”#comment-” title=”">

  218. Pam says:

    How do I show codes here?

  219. PHP Expert says:

    Thanks for the tutorial !
    We will sure use it as soon as the need comes along !
    ____________________
    Saguenay-IT, (IT Outsourcing, SOA, PHP, ASP, Flex, ActionScript, JavaScript…)

  220. Steve says:

    Reading about how the thing doesn’t work with IE6, I still can’t understand why some people stick to IE6 considering much better browsers available. IE6 is not even compatible with CSS!
    Steve, editor of westhost review

  221. Pingback: WordPress 2.7 Nested Comments With Separate Ping List | Armeda

  222. Pingback: Separating and Hiding Trackbacks with Jquery in WordPress 2.7 | Blog Tips, blogging Blog

  223. Pingback: Updated Theme | The Geekery

  224. I’m trying this on my own site, as well as yours, and it seems that the “Reply to %s” isn’t working 100%. Both my own site, and yours are still saying “Leave a Reply” when I reply to any of the previous comments. Any ideas?

    • Otto says:

      The “Reply to Person” only works when Javascript is disabled on the client. That’s the purpose of it. If the javascript is working, then you don’t need to see the Reply to X thing, since the reply box itself moves to where the reply will be. However, without the javascript, the page has to reload to get the reply-to info, and the name thing there is a visual indicator of who you’re replying to, since the reply box will be at the bottom and not in the right place.

  225. John says:

    Why does the threaded comments doesnt appear on its respective parent comment?

    I already enabled the threaded feature in the SETTINGS>DISCUSSION

    Help is really appreciated. Thanks

  226. Pingback: links for 2009-04-22 .:: [aka щямукюшт] Ozver.in | Озверин

  227. nate says:

    Thank you thank you thank you Otto.

    All the hours I wasted with IntenseDebate can now be redeemed by WordPress’ genius integration of these new comment enhancements. Not only is it completely functional, but I can make it look cool too.

  228. Pingback: Bold Feature Rundown » random process | charlie 2.0

  229. Pingback: Weiße / Leere Seite nach Kommentar – Wordpress - - ITler.NET - Der Blog für ITler und Sysadmins

  230. Pingback: Separating and Hiding Trackbacks with Jquery in WordPress 2.7 | Quest For News, A TUTORIAL Base

  231. Pingback: Separating and Hiding Trackbacks with Jquery in WordPress 2.7 | Quest For News, A TUTORIAL Base

  232. Pingback: Mastering Your WordPress 2.7 Theme & Admin Area: Tips and Tricks | Quest For News, A TUTORIAL Base

  233. Pingback: WordPress 2.7 Comments Enhancements | WordPress News - New WordPress Themes

  234. Pingback: WordPress 2.7 Comments Enhancements

  235. Robert says:

    Good rundown on changes. Very helpful.

  236. Pingback: Building Wordpress Themes – Part 12 « A Path Less Taken

  237. Pingback: The Making of a Monsta … WordPress Theme | Jeremy Adam Davis

  238. Pingback: WordPress 2.7 “Coltrane” Now Available! | Swank Web Style Blog

  239. Pingback: Mastering Your WordPress 2.7 Theme & Admin Area: Tips and Tricks | Webmaster Zone - Cyooh.com

  240. Pingback: Paintbits » Blog Archive » Lumen Reborn is here…

  241. gavin says:

    not sure if this is a good place to ask this, but I’m having a big problem with the comment permalinks. Old permalinks (from pre WP2.7) no longer work with paged comments (since they are missing a /comment-page-N/ segment, so that is a pain. But more importantly, the new permalinks aren’t in fact permalinks at all. They are completely dependent on how many comments there are per page – which can change at a blog-owners whim. Does anyone have a solution to fixing the old comment links? (which in fact would solve the permalink problem in it’s entirety since the new permalink form could be scrapped completely).

    • Otto says:

      It’s not actually possible to fix old comment links (other than turning off paging), because the links don’t contain enough information to do that. Everything after the # is not sent to the server, so WP has no idea that you’re wanting to see a specific comment there.

      As for the other thing, hey, the blog owner can change anything on a whim, so they’re as “permanent” as anything else.

      • gavin says:

        ok, fair point about ‘permanance’ – but the old comment link issue is a real problem. We need paging to reduce our page size, but we have 5 years worth of comments that include hundreds of links to previous comments – most of which are now broken.

        Is there perhaps a way to use a .haccess rule to morph a /#comment-NNN to a form which could be recognised by the server and the correct page calculation made within a plugin?

        • Otto says:

          Unfortunately, it’s not that simple.

          Everything after a hash mark in a URL literally doesn’t get sent to the server. Hash marks indicate “in-page” links. When you have a URL that looks like example.com/link/morelink#hashtag then the only bit the server gets is “GET /link/morelink”. The browser then finds the hashtag in the page and auto-scrolls to it.

          So WordPress never knows that you want to see comment-NNN, it just sees that you want the post. With links like that, it’s impossible for WordPress to know you want a comment, because the browser never tells it that fact. And you can’t even fix this with .htaccess, because the webserver itself (Apache) doesn’t get the hashtag bit either.

          So, the only solution for leaving those old links working is to not have paging.

          • gavin says:

            what about a more robust permalink structure for comments? i.e. that uses something like /2009/07/post-name/comment/123456/#comment-123456 and so is independent of any paging choices? That could get processed to always go to the correct page and the browser would still be able to find the name reference. I could go through the database making a change to the older links relatively automatically to allow for this. For reference, we have some 450 such links in our database and this would be more tractable than working out by hand what page of comments each of the old links are on.

          • Otto says:

            Hmm. Should be possible to do with a plugin.

            Essentially, the plugin would need to recognize the new URL, pull the comment ID value out of it there, then use the get_page_of_comment() function to find the page number to use. From there, you can do set_query_var(‘cpage’, NNNN) to set the comments page to whatever the result it.

            This would all have to happen before the query runs, meaning that you’re not going to get nice bits like is_single() and so forth.

            My suggestion would be to alter your links to look like /link/?comment=NNN instead. This avoids complexity, and you can just do something like $commment_id = (int) $_GET['comment'] to safely get the comment id, without opening a security hole.

          • gavin says:

            Thanks, that last suggestion sounds sensible – and in effect gives a non-paging-dependent permalink for each comment. Where would such code go though? I’ve not had much experience hacking WP at this kind of level, so I may need to see if there is anyone out there that could be motivated to help out.

  242. Pingback: 8/18/2009: Weekly Links

  243. Genry says:

    I like it! thanks!

  244. Whoa! I love this post. I hope all posts are just like this.

  245. it is quite complicated process

  246. Pingback: WordPress Glossary » wpMethod

  247. Reg says:

    Can anyone tell me how to get my blog’s comment system to work like this blog’s?
    I’ve tried IntenseDebate but it required Javascript which I don’t want. It’s also messy, where this blog’s comment system is simple in it’s layout.

    My blog can’t even get threaded comments. Any suggestions would be much appreciated.

  248. free-motor says:

    people good money

  249. dem0crat says:

    Why does the threaded comments doesnt appear on its respective parent comment?