0

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'); ?>
     </ul>
</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>
        <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)'),'  ','') ?>
        </div>
    </div>
<?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!

ty

4
  • Does it function correctly without the callback argument i.e. wp_list_comments( 'type=comment' ) ? Jul 3, 2012 at 17:31
  • No, it doesn't. What does that mean?
    – Ty Morton
    Jul 4, 2012 at 13:29
  • Glad to see you've solved it. I asked since it would rule out if your custom callback was at fault. Jul 4, 2012 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, 2012 at 16:44

1 Answer 1

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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