使用get_comments()
并将post ID作为参数传递。然后将结果打印为常规列表。来自plugin 我最近发表了:
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>\';
}
您可以这样使用它:
print t5_list_comments( array ( \'post_id\' => get_the_ID() ) );