有一个内置的函数用于查询注释get_comments
以下是一些对您的模板有帮助的内容:
$comments = get_comments( array( \'number\' => 10 ) );
if ( !empty( $comments ) ) {
?>
<ul>
<?php foreach ( $comments as $comment ) : ?>
<li><?php echo sprintf(
"<strong>%s</strong> on <a href=\\"%s\\">%s</a> : \\"%s\\" — <a href=\\"%s\\">view</a>",
$comment->comment_author,
get_the_permalink( $comment->comment_post_ID ) . "#comment-" . $comment->comment_ID,
get_the_title( $comment->comment_post_ID ),
mb_strlen( $comment->comment_content ) > 100 ? mb_substr($comment->comment_content, 0, 100) . " .." : $comment->comment_content,
get_the_permalink( $comment->comment_post_ID ) . "#comment-" . $comment->comment_ID
); ?></li>
<?php endforeach; ?>
</ul>
<?php
} else {
echo sprintf("<p>%s</p>", "No comments were found.");
}
如果您想要一个简短的代码或自定义函数,并且需要帮助,请在下面进行注释。
希望这有帮助。