I spent pretty much every waking moment I had at home this weekend trying to wrap my head around the new comment loop in WordPress 2.7. Otto’s detailed explanation was helpful, but did not give me a way to “break down” the new wp_list_comments
function.
Finally frustrated, I hit the WordPress forums and mailing lists. Several posts in the forums pointed to Justin Tadlock’s recent post about making themes backwards compatible. Basically, you save a copy of your current (2.6) comments.php file and name it legacy.comments.php. Then add a small bit of code to your theme’s functions.php file:
This IS very useful and I’ll be needing it to update my released themes, but not quite what I was looking for for updating this site. Checking WP-Hackers, I hit gold — a post by Ryan Boren a couple months back detailing how to separate pings from comments gave me the nudge in the right direction that I had been looking for.
Callbacks
I don’t know why it never occurred to me before now, but using a callback allows you to breakdown a function (similar to the foreach
loop used for comments in previous versions of WordPress). Hitting the forums again, I found a reference to Jeremy Clark’s post on using the comment callback function. This gave me exactly what I needed.
I used Jeremy’s comment threading post as a starting point for my comments.php file (view code). I fixed the alignment of most of the coding to make it a little easier to follow (and muck about, LOL).
Here’s a close-up of my modified the wp_list_comments reference:
Here I am changing the avatar size to 70 and will be using a callback function called “custom_comment” to format the results of the loop. Also, notice that the type is set to ‘comment’. For the time being, I am showing only comments (no trackbacks/pingbacks) until I figure out how I want them styled.
Now on to the functions.php file to show you how I formatted and corralled everything (view code). :)
Taking this route seems a bit overwhelming at first but IMO is the best way to go if you want your comments to look and/or behave a certain way.
Last but not least
If you haven’t already, don’t forget to add this snippet to your theme’s header.php file:
As shown in my example, make sure you add it before the wp_head()
call.
Everything clear?
I hope this all makes some kind of sense. Please feel free to ask me to elaborate on anything I’ve posted here and I’ll try my best to explain! :)
Jeremy Clark
I’m glad that my posts could be of help. Thanks for the links as well.
Jeremy Clark´s last blog post: Google Chrome 1.0
Nicki
Hey Jeremy, my pleasure. Thanks for stopping by! :)
Posts about Wordpress 2.7 as of December 15, 2008 | The Lessnau Lounge
[…] magento 1.1.8 gallery 1.5.10 phpmyfaq 2.0.10 drupal 6.8 drupal 5.14 sugarcrm 5.1.0c phpbb 3.0.4 My WordPress 2.7 comment fix – nickifaulk.com 12/15/2008 I spent pretty much every waking moment I had at home this weekend […]
Jo
Does this mean that if I follow your instructions, I can save my hair and my comment section will be as nice and clean as yours?
Nicki
LOL, Jo, holler at me if you have any problems. :)
brokencode
I have not check the code yet. Thanks for sharing ;)
brokencode´s last blog post: Twitter goes connected with Google
TimurAlhimenkov
I really liked this post. Can I copy it to my blog?
Thanks in advance.
Sincerely, Timur.
Nicki
I would prefer that you link to it instead. ;P
Otto
I’ve been doing a lot of work converting themes to threaded comments lately, so when I saw this, I couldn’t help but notice one minor omission.
If you wrap the comment into a div with a unique ID, then add an add-below to your comment reply link, you’ll get the correct javascript handling to move the comment reply around properly.
Example of how to change your callback to do that is here: http://pastebin.com/f6d1fc223
One other change you’d have to make is to alter the comment reply form so as to encase it in a DIV with an id of “respond”. Since you already have a paragraph with this ID, you’d have to adjust that somewhat.
Your comment reply form also has an extraneous comment_post_ID field. The comment_id_fields() function adds that, it’s not necessary to have it explicitly in the theme anymore.
With those minor adjustments, you’ll find that the comment form moves to where your reply link is, instead of the other way around.
Nicki
Hey Otto, thanks for stopping by! I appreciate the tips and had been wondering about the reply link thing, but hadn’t had time to research it. Danke! :D
Otto
A good source for examples of converted themes is the themes used on WordPress.com, which are available via SVN here: http://svn.automattic.com/wpcom-themes/
I recently converted all those themes to support the new comments threading and paging features, and hopefully there will be an announcement soon about them all being enabled on WordPress.com. However, the changes are there now, and you can look at them for ideas on how to do things.
Otto´s last blog post: Spotted in Savannah
Nicki
Nice. Thanks again! :)