Display comments on a comment page without form

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() ) );

Leave a Comment