WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a client site that has requested a custom comment format for posts of a specific category.

In my loop template, I have this:

<div id="gallery-commentlist">
     <ul class="gallery-commentlist">
          <?php wp_list_comments( 'type=comment&callback=gallery_comment'); ?>
</div><!-- #gallery-commentlist -->

And in my functions.php file, I have this:

<?php function gallery_comment($comment, $args, $depth) {
   $GLOBALS['comment'] = $comment; ?>
   <li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
     <div id="comment-<?php comment_ID(); ?>">
        <div class="gallery-comment-body">
            <p><span class="gallery-comment-author"><?php comment_text() ?>:</span> <?php comment_text() ?></p>
        <div class="comment-meta commentmetadata"><a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ) ?>"> &ndash; 
        <?php get_comment_date() ?> at <?php get_comment_time() ?></a><?php edit_comment_link(__('(Edit)'),'  ','') ?>
<?php }?>

It's not returning any comments, but for the life of me, I can't figure out why. I followed the instructions in the WP codex to the letter. Is there something that I have overlooked?

Thanks for any help!


share|improve this question
Does it function correctly without the callback argument i.e. wp_list_comments( 'type=comment' ) ? – TheDeadMedic Jul 3 '12 at 17:31
No, it doesn't. What does that mean? – Ty Morton Jul 4 '12 at 13:29
Glad to see you've solved it. I asked since it would rule out if your custom callback was at fault. – TheDeadMedic Jul 4 '12 at 16:40
Thanks for the help. I should have thought of the solution sooner, since I recently struggled with setting up a custom query to override wp_query. It didn't occur to me that it would do the same thing with comments. I thought it behaved more like a straight up template placement. Live and learn. – Ty Morton Jul 4 '12 at 16:44
up vote 0 down vote accepted

There is apparently some sort of query call that takes place as part of the comments_template() call, just as there is with loop calls.

When I put my custom function in the comments template, it works perfectly.

I tried putting the entire contents of the comments template into my custom loop-single template, and it didn't work.

The solution wound up being placing an if{} statement in the comments template, and then setting up two different layouts based upon the results.

Now it all works like it should.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.