[wp-hackers] Uneasy over the Walkers

Otto otto at ottodestruct.com
Sat Mar 28 20:43:14 GMT 2009

Actually, the callbacks can be relatively simple. When I spent a month
upgrading all the wordpress.com themes, I did a lot of those
callbacks. Here's the basic methodology to it.

1. Determine the style of the comment. Hopefully, it's a UL-LI style.
Those are easiest. OL-LI is almost as simple, but it's best to do it
in UL mode instead. If you want numbering, you can add it via styles
anyway. A nested DIV mode is trickier, and anything else is probably
too difficult to mess with.

2. Create a function at the top of the comments.php file. I prefer to
put it here because it's slightly more efficient and it keeps the
comment function in a more obvious location. Make it look like this:

function themename_comment($comment, $args, $depth) {
	$GLOBALS['comment'] = $comment;
	extract($args, EXTR_SKIP);
.. other stuff here...

3. That "other stuff" is basically going code to display one comment.
It'll look something like this (UL-LI case):

<li <?php comment_class(); ?> id="comment-<?php comment_ID() ?>">
<div id="div-comment-<?php comment_ID() ?>">
	<div class="comment-meta">
		<div class="comment-author vcard">
		<?php if ($args['avatar_size'] != 0) { echo get_avatar( $comment,
$args['avatar_size'] ); } ?>
		<strong class="fn"><?php comment_author_link() ?></strong>, <?php
_e('on'); ?> <a href="#comment-<?php comment_ID() ?>" title=""><?php
comment_date('F jS, Y') ?> <?php _e('at');?> <?php comment_time()
?></a> <?php _e('Said&#58;'); ?> <?php edit_comment_link('Edit
Comment','',''); ?>
		<?php if ($comment->comment_approved == '0') : ?>
		<em><?php _e('Your comment is awaiting moderation.'); ?></em>
		<?php endif; ?>
	<?php comment_text() ?>
	<div class="reply">
		<?php comment_reply_link(array_merge( $args, array('add_below' =>
'div-comment', 'depth' => $depth, 'max_depth' => $args['max_depth'])))

Notice a few things about that code.
- It starts with an LI but does not close the LI. This is because the
LI is closed automatically, and threaded comments need to be inside
that LI.
- comment_class(). Use it. Love it.
- You need a DIV surrounding your comment, and it needs to have the ID
just like I used above. This is for the reply javascript to find your
comment to move the reply box to it.
- You can style the meta bits however you like, but if you're smart,
you'll put them in something with a class of "vcard". This makes them
an hCard microformat, as they output the necessary bits automatically
(get_avatar does, at least). Also include the comment_author_link in
an "fn" class to get this to work properly.
- The comment_reply_link needs a fair number of parameters. Just use
the ones I give you there. The "div-comment" in the add_below
parameter is what tells the javascript where to find your comment, in
order to move the comment box below it.

There's other bits as well. You still need to add the comment-reply
script into the header.php, and the comment form needs to be modified
slightly if you're doing a full conversion of an old theme to a new
one. If you need more customization, you can add an end_callback
function as well, to control the ending of the comment (stuff before
and including the closing LI). If you're doing a DIV style, you'll
need to add style=div into the wp_list_comments call as well. It can
be complex, but generally it's pretty straightforward once you get
used to it.

Sent from: Memphis Tennessee United States.

On Thu, Mar 26, 2009 at 2:52 PM, Simon Wheatley
<simon at sweetinteraction.com> wrote:
> On Thu, Mar 26, 2009 at 3:25 PM, Joost de Valk <joost at yoast.com> wrote:
>> no need, you can simply do a callback:
>> <?php wp_list_comments('type=comment&callback=yoast_comment'); ?>
>> the callback function can look like this:
>> function yoast_comment($comment, $args, $depth) {
>>    $GLOBALS['comment'] = $comment;
>>    comment_text();
>> }
> Well that's better than overriding a class, etc, as I'd assumed;
> however it's still not as simple as modifying single.php or most of
> the other templates, also with the new threaded commenting the
> callback function would need to be fairly complex... I know I'm
> moaning, and I know this is recursive and relatively complex code, but
> do you see where I'm coming from? Maybe I should stop going on as I
> don't have a code solution for this.
> S
> ---
> Sweet Interaction Ltd is Registered in England/Wales, no. 6610741
> Registered office: 7 Malton Av, Manchester, M21 8AT
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers

More information about the wp-hackers mailing list