admin管理员组文章数量:1332889
Following is my code which I am using to display comments of posts in a loop (Custom Post Types). I would like to display only latest 3 comments. Kindly help me to limit comments.
<?php foreach (get_comments() as $comment): ?>
<div><span class="author-name"><?php echo $comment->comment_author; ?> said:</span> <span class="author-cmnt">"<?php echo $comment->comment_content; ?>".</span></div>
<?php endforeach; ?>
Following is my code which I am using to display comments of posts in a loop (Custom Post Types). I would like to display only latest 3 comments. Kindly help me to limit comments.
<?php foreach (get_comments() as $comment): ?>
<div><span class="author-name"><?php echo $comment->comment_author; ?> said:</span> <span class="author-cmnt">"<?php echo $comment->comment_content; ?>".</span></div>
<?php endforeach; ?>
Share
Improve this question
edited Jul 1, 2020 at 12:58
mozboz
2,6281 gold badge12 silver badges23 bronze badges
asked Jul 1, 2020 at 10:35
AbirAbir
112 bronze badges
2 Answers
Reset to default 1I don't usually work with comment so my suggestion is untested, but I see that get_comments() receives an array of args.
Try this:
$comments = get_comments(array("number" => 3))
and instead of your foreach loop:
foreach ($comments as $comment):
My answer to this is to use something like this:
$args = ['number' => 3];
$comments = get_comments( $args );
本文标签: Limit number of comments from getcomments()
版权声明:本文标题:Limit number of comments from get_comments() 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742294612a2448469.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论