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; }
The Comments Loop
The Comments Loop used to look similar to this (much simplified from a real one):
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.
Good rundown on changes. Very helpful.
[...] posted here: WordPress 2.7 Comments Enhancements Tags: Comments0 Leave a Reply Click here to cancel [...]
[...] WordPress 2.7 Comments Enhancements Share and [...]
[...] comments compatible with WordPress 2.7 should be your first step when you edit your theme files. Otto has written a detailed post on the new comment enhancements in WordPress [...]
[...] in the ol’ comment file in Wordpress 2.7. I highly suggest taking a peek at Otto’s WordPress 2.7 Comments Enhancements if you haven’t already. He outlines how the new comment loop works, and all the spiffy [...]
[...] in the ol’ comment file in Wordpress 2.7. I highly suggest taking a peek at Otto’s WordPress 2.7 Comments Enhancements if you haven’t already. He outlines how the new comment loop works, and all the spiffy [...]
[...] Erweiterte Kommentar-Funktionalität ab Wordpress-Version 2.7 (siehe auch Wordpress-Info) Stimmen die Einstellungen nicht überein, kann es zu diesem Problem [...]
[...] the way I wanted. I’m planning on writing a few tidbits for others in the same position. Even Otto’s excellent post didn’t quite do [...]
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.
[...] WordPress 2.7 Comments Enhancements (tags: wordpress comments themes tutorial theme tutorials tips howto wordpress-2.7) [...]
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
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?
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.
[...] actually supports it natively, you just have to update your themes. I found a great reference here which detailed how to do it, but it seemed to not work, so I went in search of more details. [...]
[...] in the ol’ comment file in Wordpress 2.7. I highly suggest taking a peek at Otto’s WordPress 2.7 Comments Enhancements if you haven’t already. He outlines how the new comment loop works, and all the spiffy [...]
[...] WordPress 2.7 Comments Enhancements by Otto [...]
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
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…)
How do I show codes here?
My code did not show, wait here it is:
commented on <a href=”#comment-” title=”">
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?
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(); }
nevermind – i think i found it here: http://c.hadcoleman.com/2009/0.....dpress-27/
Hello & thanks for this great Post…! Just testing out the comment functionality.
Thanks. I have been searching google for hours on how to style and enhance wordpress 2.7 comments.
[...] There is new codex entry for theme authors specifically, check out Migrating themes to 2.7 and also read otto’s post regarding WP 2.7 comment paging and threading. [...]
I use your comments.php but I don`t see a “Reply to this Comment” link for each comment. What could be wrong?
Did you turn on threaded comments in the Settings->Discussion area?
What I must do in the Settings->Discussion area?
thank you for reply my problem
You’d have to turn on the threaded comments for there to be a reply link.
?? 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
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.
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?
It`s work Yay! Thank you
but the comments form open little bit long and little bit difficult.
Not direct open
Would you help me please?
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.
[...] WordPress 2.7 Comments Enhancements [...]
[...] WordPress 2.7 Comment Enhancements – Make your WordPress theme ready for the new comments enhancement introduced at version [...]
[...] If you don’t know how to enable threaded comments on your WordPress 2.7 blog, check out how to activate threaded comments here. [...]
I coudn’t manage to make it work… I can’t get even a “reply” link for each comment. What could be wrong?
Same here
No “reply to comment” and no threading using your comments.php(s)
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.
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.
[...] support for WordPress 2.7 enhanced comments features. Thanks to Valerie for the heads up and Otto for the [...]
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.....an-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,
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.
[...] Themes auswirken können. Vor allem die Kommentarfunktion soll betroffen sein und kann wie in verlinktem Blog angepasst [...]
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.
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
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.
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.
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.
[...] to add. Especially with the Threaded Comments, which took the most time working on following the Enhanced Threaded Comments tutorial and having to tweak the functions.php file to get it neat. And finally, there’s the color [...]
hi otto,
how do yo display alternating comments styling with this new tag?
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
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
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
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.
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
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.
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
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?
it might just be that I’m on such a slow connection at the moment that I forgot I refreshed
[...] 18, 2009 ( 0 ) Building a WordPress theme for a client last week, I realized a glaring issue with version 2.7’s threaded comment feature – it attaches odd/even classes to both comments and replies, screwing up the zebra-stripe effect [...]
[...] A tutorial at ottodestruct.com [...]
Thank you very much je te remercie du fond du coeur pour ce tutoriel !
Bonne continuation, good luck
[...] Bookmarked a link on Delicious. WordPress 2.7 Comments Enhancements [...]
[...] threading. Assuming you’ve got 2.7, turn on comment [...]
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?
Finally all the info about comments in one place. Thanks!
Great tutorial, thanks a lot, I am going to modify my themes now.
[...] Migrating Plugins and Themes to 2.7 / Enhanced Comment Display WordPress 2.7 Comments Enhancements [...]
[...] WordPress Themes auf Wordpress 2.7 aktualisieren [...]
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!
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?
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 ?
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?
[...] WordPress 2.7 Comments Enhancements Bien comprendre et utiliser le nouveau système de commentaires de Wordpress 2.7 [...]
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?
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.
[...] the Default theme that comes with Wordpress 2.7 (/wp-content/themes/default/comments.php) OR follow Otto’s instructions to add threading AND inline replies. (Obviously, before you go about changing any files in your [...]
Just testing out the comment functionality. Great Post!
[...] If you don’t use nested comments, look into it immediately. If you use WordPress 2.7, you already have all you need built in. You may just need to edit your comments.php file to make it work if you upgraded from an older version of WordPress. The good news is that a lot of free/premium now work with WordPress 2.7 so you won’t have to worry about editing any files to make nested comments work. If you don’t have a theme compatible with the new nested comments features, check out Otto’s post on how to make your comments nested in WordPress 2.7. [...]
[...] komplett umgestellt wurde. Wer sein Theme auf die neuen Funktionen hin ändern will, findet hier (en.) oder hier (dt.) eine schöne [...]
I notice it does not happen on your blog.
Your blog has
http://www.myblog.com/content/.....omment-305
instead of
http://www.myblog.com/content/.....omment-305
So, I have this extra >>> comment-page-1#
Thx for any help.
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.
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?
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?
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.
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/.....omment-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.
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......comment-30
Anything you know about working around that problem?
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.
I agree with you but, I think he is looking to display a message when “the reply link stops showing up.”
[...] Enable some plugins: I’m having a little trouble with the quicktag plugin; the buttons show up, but they don’t do anything when clicked. I also have to figure out how to add comment counts to the new WP comment loop. [...]
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/img.....re1nd6.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.
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.
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
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
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?
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.
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!
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.
Thanks, I made that change. Good point.
Page comment will cause duplicate meta data detected by google, but I have to use it for some reasons.
Awesome Tutorial… just used it to build me new theme
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.
[...] 2.7 now includes comment enhancements that include password protection checks and improvements to security from previous versions such as [...]
Wait… is it just me or do authors whose comments are replied to NOT receive email replies? Isn’t that the whole point??
WordPress does not have email reply functionality yet, but there are plugins that can do that sort of thing.
The 2.7 update only adds threading and paging of comments.
thanks for this tutorial
To be honest, it WAS much simpler to take your code and copy & paste it in.
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!
[...] comments compatible with WordPress 2.7 should be your first step when you edit your theme files. Otto has written a detailed post on the new comment enhancements in WordPress [...]
[...] you're going to use comment threading, paging, etc then this page has some useful info on it on some important things you'll need in your theme [...]
[...] let me say many thanks to Otto for getting this code all [...]
Thanks, this worked great!!
[...] for the threaded comments in Typograph. These were Chris Harrison’s blog (for styling) and Otto’s blog for backend code. Thanks go out to the both of them for excellent tutorials and to Otto for some [...]
[...] WordPress 2.7 Comments Enhancements [...]
[...] of very busy. Instead of repeating all the info about the comment updates, just head over to the WordPress 2.7 Comments Enhancements post from [...]
[...] is very little documentation yet on this tag but some more info can be found here, here and here. I guess to style the comments you would need something called a custom callback function in your [...]
Thank you very much for those explanations and the file which works very well !
[...] sans plugin. J’ai simplement copié/collé le fichier comment/php que j’ai trouvé ici. Je remercie l’auteur de ce fichier, que j’aurais été bien incapable de créer [...]
[...] Fully implement WordPress 2.7’s Enhanced Comment Display features. [...]
Great explanation! Thanks a bunch.
Love it, thanks for the tutorial
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.
Awesome tutorial!
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.
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.
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.
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.
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.
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.
Thanks, it’s useful for me.
OK bye
[...] comments compatible with WordPress 2.7 should be your first step when you edit your theme files. Otto has written a detailed post on the new comment enhancements in WordPress [...]
[...] aktivieren und damit diese dann auch richtig funktionieren, sind einige Anpassungen nötig, die auf ottodestruct.com detailliert beschrieben werden. Jetzt müsste ich mich nur mal erkundigen, wie man Pingbacks von den restlichen Kommentaren [...]
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.
[...] I started reading this, that and finally this post. If you’d like to understand what you’re doing I recommend reading these [...]
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.
[...] comments compatible with WordPress 2.7 should be your first step when you edit your theme files. Otto has written a detailed post on the new comment enhancements in WordPress [...]
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.
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?
How I go about inserting this code:
if ( is_singular() ) wp_enqueue_script( 'comment-reply' );in my theme’s header.php file?
Err… Not sure I understand the question. You edit the file and paste in that code. What more do you need to know?
Yes Make sure it’s in php tags and comes right before wp_head as explained.
[...] Meer informatie kun je ook vinden in het Engelstalige artikel van Otto. [...]
Thank you very much for this tutorial, I was able to update my theme thanks to your help!
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?
It is easier, and you can do both I think.
The whole of the last section, under “Styling” covers exactly this.
Thanks for the help. Now i added new comment support on my themes. And its working perfectly. Thanks again..:)
[...] http://ottodestruct.com/blog/2.....ancements/ [...]
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,
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.
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.
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/
Nice touch with AJAX.
[...] comment threading, at least, if the theme supports it. So after a few tweaks and going through Otto’s article a number of times until I finally understood how it works, I was able to use the new feature in my [...]
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 !
Did you actually *turn on* the comment threading after making the changes? See the Settings->Discussion page in wp-admin.
Forget me
I forgot to check in the admin panel.
Great article !
Let’s go styling now !
[...] comments.php template so I could make use of the built-in threaded comments. I took a read of this useful article detailing the steps to alter the template file, and did everything it asked (or so I [...]
[...] so I can take advantage of the threaded comments. If anyone else needs to do this I found a great article on the changes you’ll need to [...]
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!
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 closingtags. The problem is that you put the last closingat the END of the file. It needs to be in the middle of the last twostatements.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.
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.
how you colorize your comments? can you please tell me any easier hacks and thus I can input to my site. thanks again.
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.
This is so very confusing to me. I’m reading, fiddling with code, reading, etc and I’m still completely lost.
nice post… very helpfull
[...] Basado en WordPress 2.7 Comments Enhancements [...]
[...] WordPress 2.7 Comments Enhancements from OttoDestruct.com [...]
[...] The instructions, are here on the Wordpress codex, though I should repeat their link and thanks to OttoDestruct, which is where I found the instructions [...]
This is a great article!
[...] comments compatible with WordPress 2.7 should be your first step when you edit your theme files. Otto has written a detailed post on the new comment enhancements in WordPress [...]
[...] spent several hours playing with this blog’s comments. I used this post as a guide and, in general, had things working quite [...]
[...] em um outro blog é necessário fazer diversas alterações no tema utilizado. Para ajudar, há um blog que ensina quais as alterações devem ser feitas e um outro que mostra um exemplo do código [...]
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?
You have some blank lines or something at the end of your functions.php file. According to that error message, line 8 produces output.
[...] comment threading functionality is also a neat feature. It requires from theme modifications – but fortunately not to heavily [...]
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!
Fantastic release, I’ve just started upgrading my blogs to use it. Nice clean and easy to use interface.
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?
That is the default behavior, if you add the wp_enqueue_script line to the header.php file, as I describe in the article above.
I actually do have
and I can see that it is being rendered in the source. Any other ideas? Thanks for the help… awesome tut.It should not be rendered in the source. It’s a PHP function, it should cause a script tag to be rendered. Specifically, a script tag to wp-includes/js/comment-reply.js.
If you’re seeing wp_enqueue_script in the source, then you need to wrap that stuff in PHP tags.
I should have specified, I meant that I see the .js file being rendered in the source.
Here is my site if that helps. I have the js and the anchor… no idea why it wouldnt work. For some reason when I click reply the page refreshes
http://siriusbuzz.com/big-thre.....ick-up.php
Now you have to tell me how you get the urls in your comments to truncate! Awesome.
This plugin shortens the URLs in comments: http://www.village-idiot.org/a...../wp-chunk/
Have you noticed any issues with it in 2.7? His page doesn’t say that it works in 2.7 officially although it seems fine judging by your site.
The plugin works fine in 2.7. Most plugins that don’t do anything complicated tend to work in many versions of WordPress for a long time.
Everything seems to work fine except for the following:
php comment_form_title( ‘Leave a Comment’, ‘Leave a Reply to %s’ )
For some reason all it ever says is “leave a comment” even though I am replying to a person and that reply is correctly nested upon submit. Any ideas? You’re the man, I dont know what people would be doing without this article.
I see your “leave a reply” does not change either… is this by design?
The “Leave a Reply” does not change when the comment-reply javascript is used. It only changes when that is broken and the page has to refresh in order to make the comment reply work. That way you know who you’re replying to even when the form can’t move directly underneath them dynamically.
I guess its all working perfectly then. Thanks again for all the help, it is greatly appreciated.
It seems as though you need to have the cancel link or the whole thing does not work. Why would that code be a requirement?
Because the javascript is looking for that cancel link in order to add code to it, and if it doesn’t find the link, then the javascript stops processing properly.
[...] ATTENZIONE QUESTO CODICE NON E’ RETROCOMPATIBILE QUINDI SE VOLETE AVERE UN CODICE CHE FUNZIONI CON LE VECCHIE VERSIONI DI WORDPRESS E ANCHE CON LA 2.7 SEGUITE QUESTO TUTORIAL. [...]
[...] more details? Check out Otto’s WordPress 2.7 Comments Enhancements article on his blog. Very informative and worth a look if you do a lot of theme [...]
[...] Otto, den mach einer eventuell wegen seiner iTunes-Javascripts schon kennt, hat da eine sehr feine Zusammenfassung, mit dir ich in unter 10 Minuten mein Theme angepasst hatte. Es braucht zwar noch ein wenig [...]
Thank you. I got the threaded comments to work. Excellent job in posting this very helpful article.
[...] habe ich das mit der Anleitung von Thoma Stachl. Zusammen mit den Anleitungen von Texto und Otto habe ich die neuen Kommentarfunktionen einbauen [...]
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.
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.
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.
[...] de bulunuyor. Tabi bu scripti de temanıza entegre etmeniz gerekiyor. Daha detaylı bilgi için Otto‘nun yazdığı detaylı dökümanı inceleyebilirsiniz. Entegrasyonla ilgili problemleriniz [...]
It’s possible to separate count on comment and trackback? How to use that?
Testing a reply to a comment
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.
[...] WordPress 2.7 Comment Enhancements Otto dissects the new comment functionality in WordPress 2.7. He shows you how to create a WordPress 2.7 compatible coments.php. [...]
[...] you, Otto, your 2.7 Comments Enhancements instructions were a big help. [...]
[...] developers while adapting your own WordPress theme to the new comment system. Can you do that? Yes, thanks to the great tutorial by Otto! Justin Tadlock has also proposed us a method to create a WordPress 2.6 and 2.7 compatible [...]
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?
Yes, they switched WP.com over to the new 2.7 interface a couple days ago.
Excellent, testing this out.
i’m just testing too. Great
[...] there are changes to the front end, like a more advanced comments system, and I’m sure a countless number of little enhancements, but front ends are the domain of the [...]
[...] step tutorials on how to incorporate this new functionality, so rather than reinvent the wheel read this post by [...]
[...] are now threaded, without any third party plugins. You probably need to edit your theme to enable these comments, but if you use the default theme threading is enabled automatically. [...]
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!
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?
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.
Thanks. I still have lot of trouble customizing the style, but that helps.
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!
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?
[...] Ottodestruct – WordPress 2.7 Comments Enhancements [...]
Hi,
How could I get the comment count to count only comments and no replys?
thanks in advance.
And how to collapse the threaded comments, to hide(-) or show (+)???
another question, how to implement email notify to parent?
Neither of those are built-in, you’d have to make a plugin or something to do that sort of thing.
Thank you Otto, on the first one maybe with CSS / Mootols, on second one i have no idea yet. Best Regards!
[...] Major code changes. I think this post on Wordpress 2.7 Comments Enhancements will do a better job of explaining the changes. [link] [...]
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!
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.
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.
[...] Ottodestruct – WordPress 2.7 Comments Enhancements [...]
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?
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.
[...] to Otto for this great post on the heads up on the new comment system for WordPress 2.7. After I read this I decided to get [...]
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.
Same thing here! It would be great to know all the parameters.
Doesn’t look like there’s a way to change that line yet. (http://trac.wordpress.org/brow.....php#L1158)
[...] As Wordpress 2.7 has backwards compatibility with themes built for previous versions, I had no issues on that front either. The hardest part was implementing new features, like comment threading. I found this guide to be very helpful. [...]
[...] Ottodestruct – WordPress 2.7 Comments Enhancements [...]
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
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.
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.
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.
Thanks, Otto!
I was thinking I’d broken my theme by fully updating it… Lol.
It wouldn’t be the first time for me, either.
Now to go and get beta 3, and think about how I’m going to theme it for http://www.londonscallings.co.uk
Thanks,
Matt.
[...] feedback. – Make your themes comments compatible with WordPress 2.7 and earlier versions. – WordPress 2.7 Comments Enhancements: An in-depth post on the changes WordPress 2.7 brings to theme [...]
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?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.
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.
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/m43b50f3eSo how i can add custom reply link to my comments? I can’t.
Sorry for bad English.
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>
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).
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 usingif ( $comment->comment_approved == '0' ).What is the new function to check this?
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”.
[...] Ottodestruct – WordPress 2.7 Comments Enhancements [...]
Fine! As I installed wordpress 2.7 turn me down here to put all this into practice … Greetings!
[...] The answer is yes, with thanks to a few lattes, 2 1/2 hours and posts that I’ve read from Otto and [...]
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)
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).
[...] WordPress 2.7 is not due till at least end November. However you can always get a sneak peak of the freshly redesigned admin together with other cool features in Beta 1. For theme developers, are your themes going to take advantage of the new commenting features like paging and threading? Will it be 2.7 capable? [...]
[...] themecreators or people who made their own theme can be found here at justintadlock.com and here at ottodestruct.com [...]
[...] WordPress 2.7 Comments Enhancements Przystosowywanie szablonu graficznego do nowego systemu komentarzy. [...]
[...] Otto Pour la seconde solution, il [...]
Well, I know what I’m going to be doing this weekend! Good post, very useful, thanks.
[...] A reference of how to enhance your comments file, from Justin Tadlock’s early preparation for 2.7 and Otto’s WordPress 2.7 Comments enhancement. [...]
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.
[...] Just recently, I figured out that Comment Threading is not enabled on this blog, and that Paged Comment is also no where visible here. After a couple of minutes of tinkering what could have been wrong, I noticed a couple of new WordPress News Flash on my other blog’s 2.5 dashboard. And the notices go like this.Making your Theme’s Comment Template 2.7 Compatible. It’s one of the toughest tasks to do for someone like me who does not loves playing around with either the CSS or with the Comment Template that I recently fixed from a couple of errors that came up when I edited it. And now, I have to dig down the codes and prepare for another couple of hours of edit to make things right for 2.7, since this blog runs on 2.7.*after 2 hours of downtime later*So, let me continue this post. I have tried what a reader of Weblogtoolscollection.com has tried, but I literally failed with it. Looks like I have to find myself comfortable using the Comment Remix Plugin for the mean time.As you noticed in the text above which is contained in the asterisks, I had a 2 hour down time again across all my blogs and have almost bought another domain mapping on WordPress.Com for my Poetry Site which I really want to continue. But time just doesn’t allow me to, especially these unpleasant events.To make some sense out of all these complaints and rants in this post, here are a few links that could aid you in making your theme compatible with the new WordPress Comment Template and the features it brings like Comment Paging, Comment Threading and even more.Make your Comment Templates 2.7 and backwards compatibleDetailed Post about adding the Comment enhancements [...]
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.
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.
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.
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'
));
[...] followed Otto’s notes on WordPress 2.7 Comments Enhancements. I took advantage of the new enhanced child theme templates at the same time by making my changes [...]
Thanks for this post, this is the information that I was looking for.
I am just working on comment enabling for my image gallery.
[...] we are on the subject of comments and WordPress 2.7, They have also written a detailed post on the new comment enhancements in WordPress 2.7. Judging from the comments and reading through the article, it is a very well written peice and [...]
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.
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’);
[...] a great write-up about this on Otto’s blog that talks about the changes that exist and how they can be implemented. The new functions [...]
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
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.
Thanks Otto.
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
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.
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.
[...] feedback. – Make your themes comments compatible with WordPress 2.7 and earlier versions. – WordPress 2.7 Comments Enhancements: An in-depth post on the changes WordPress 2.7 brings to theme [...]
Actually, forget what I said. It was an error in my template it seems.
[...] you want to get started with 2.7 theme migration have a look at Otto’s or Matt’s posts on the new comment system and ping/comment separation. Related [...]
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-pag...../#comments. Can somebody confirm this? Just append some GET parameter and follow a next or previous comments page link.
[...] Take for example, this site’s theme. Customizing the comment form alone gave me headaches for weeks. But I did learn a great deal when it comes to theme customizations and functions when using WP2.7’s built-in comment threading. [...]
[...] take a while (the tutorial to modify your theme files to support WordPress 2.7 threaded comment is here). digg_url = “http://www.michaelaulia.com/blogs/wordpress-27-beta-1.html”; [...]
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.
Scott the numbers are from the ol list
div#comments ol.comments{ list-style:none;}and than there are no numbers
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.
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.
[...] out Otto’s WordPress 2.7 comments enhancements tutorial to add all the extra features to your theme’s comments [...]
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
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
–
and if you define 1 with color black and 4 with color green -green is the winner
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
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.
[...] Ottodestruct – WordPress 2.7 Comments Enhancements for Themes [...]
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!
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.
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
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.
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
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.
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
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?
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
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.
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!!!!
Is there a way to change “Reply” by something else ?
Not yet, but I’ll mention it on trac so that it can get in by 2.7.
Done. In the latest trunk, you should be able to pass a “reply_text” argument to the wp_list_comments to set the text of the “Reply” link.
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();
The state of the code in trunk changed since I first wrote this guide, as Ozz explains over here.
I’ve updated the guide accordingly.
Where did you update the guide? I cannot find “comment_parent_field();”
Thanks
The comment_parent_field function is gone now. It’s been replaced by comment_id_fields, which does both the parent field and the post id field.
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…
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/2.....o-threade/
I’ve updated the post to account for the latest trunk code. I’ll try to keep it that way.
Great news, thanks.
Yeah!
I wanna try cause it’s really exciting
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.
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?
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.
Maybe the plugin author can make a “fix” to address this issue if it occurs.
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.
[...] WordPress 2.7 Comments EnhancementsWP 2.7 is due out in Nov08 and has major changes to comments handling. This article from one of the core developers identifies changes to make to themesnone [...]
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.
No, it doesn’t, but that is a good idea.
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
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.
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.
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.
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?
Non-modified themes will continue to work in WordPress 2.7 (they do now anyway). They just won’t have the new threading or paging functionality.
So upgrading doesn’t mean making sure your theme is up to par in advance, you can fix up the theme after the fact.
Good to know. Thank you.
Awesome. My theme could be even better than before with this power
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/
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.
Wow. That was fast. Thanks, Otto.
Thanks Otto, good insider information as always!
This means I will have to do some work on my comment.php ? Oh, no, my God !
it is quite complicated process
[...] has written an excellent article on how to prepare your sites for the new Comments [...]
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
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
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.
That’s above my pay grade.
As I said, I’m PHP challenged.
But if someone wants to build a Quoter liberator.
Peace,
Gene
Hi Otto,
The article is great. Can you add a sample comments.php ?
[...] WP 2.7 Comments Enhancements→ [...]
You’re a beast! Thanks for this. …back to work.
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..?
Hopefully this article will be useful to theme developers though, It can be a bit confusing at first following the default themee layouts.
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.
Excellent advice, thanks.
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?