Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm using this to allow me to display my comments for posts on category pages:

<?php
$wp_query->is_single = true;
comments_template();
$wp_query->is_single = false;
?>

However I don't want to display the comment form. Is there a way to display the comments only on a comment page?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Use get_comments() and pass the post ID as parameter. Then print the result as regular list. From a plugin I have published recently:

function t5_list_comments( $atts, $content = '' )
{
    '' !== $content && $content = wpautop( do_shortcode( $content ) );

    if ( ! isset ( $atts['post_id'] ) )
        return 'Please pass an argument for "post_id"';

    if ( ! $comments = get_comments( $atts ) )
        return 'No comments found for post ID '. esc_html( $atts['post_id'] );

    $out = $content . '<ul class="t5-comment-list">';
    foreach ( $comments as $comment )
    {
        $out .= sprintf(
            '<li>%1$s - %2$s %3$s</li>',
            get_comment_author_link( $comment->comment_ID ),
            get_comment_date( 'd.m.Y H:i', $comment->comment_ID ),
            wpautop( $comment->comment_content )
        );
    }

    return $out . '</ul>';
}

You can use it like this:

print t5_list_comments( array ( 'post_id' => get_the_ID() ) );
share|improve this answer
    
this works great, just can't figure out how to format the comment date using wpautop( $comment->comment_date). Any idea? –  JonnyPlow Jan 15 '13 at 21:09
    
@JonnyPlow See my update. –  toscho Jan 15 '13 at 21:25
    
thanks a bunch, works wonders! –  JonnyPlow Jan 15 '13 at 21:35

Your Answer

 
discard

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.