【发布时间】:2017-03-30 08:59:37
【问题描述】:
<?php $counter = 0 ?>
<table>
<?php foreach($attributes as $a): ?>
<tr>
<td><?php $a['name']?></td>
<td><?php $a['Price']?></td>
</tr>
<?php $counter++;
if ($counter > 3) ?> <!-- What to do here? -->
<?php endforeach; ?>
</table>
在这样的 PHP 块中,我希望在三个 tr 元素之后有一个阅读更多按钮,当我单击该按钮时会显示所有其余元素...
与 PHP 有什么关系?
【问题讨论】:
-
你可以使用 ajax 来实现。在该按钮上单击(阅读更多)使用 ajax 调用添加新的 trs。点击此链接:/load-more-data-using-jquery-ajax-php-from-database 这是一个从数据库加载更多/读取更多数据并将其放入 html 的示例。
标签: javascript php wordpress foreach