我对 PHP 的了解非常有限,所以我立即询问。
我使用的是基于 Bootstrap 的网站,在显示“阅读更多评论”之前,每个帖子最初默认显示 13 条评论(最多)。
我正在寻找一种方法将显示的评论限制为 2 条而不是 13 条。
有人拥有实现这一目标的必要知识吗?
提前非常感谢
<li class="pp_post_comms hidden"></li>
<?php if ($post_data['comments']) {
foreach ($post_data['comments'] as $key => $comment) {
include 'comments.html';
} } ?>
<?php if ($post_data['votes'] > 4) { ?>
<li class="load-comments">
<button onclick="load_tlp_comments(<?php echo $post_data['post_id']; ?>,this);">{{LANG show_more}} {{LANG comments}}</button>
</li>
<?php } ?>
</ul>```
最佳答案
在您的 SQL
查询中,在查询末尾添加 limit 2
例如
SELECT * FROM comments WHERE post_id = ? LIMIT 2
关于php - 如何限制显示评论的数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58014395/