Smarty模板与分页

时间:2013-10-28 07:47:36

标签: php smarty

我开始学习聪明,我有这样简单的代码来显示页面上的所有博客文章:

{foreach from=$posts item=post}
<div class="posts">
 <div class="title">
  <a href="{$post->getUrl()}"><h3>{$post->getTitle()}</h3></a>
</div>
<div class="content">
  {$post->getContent()}
  <hr />
</div>
</div>
{/foreach}

我正在浏览一系列帖子并在页面上显示它们。但我想加入分页。例如,每页只显示10个帖子。如果有超过10个帖子,请在其他页面上显示。

有什么建议吗?

1 个答案:

答案 0 :(得分:0)

使用php,只需将前10个帖子放在您发送给smarty的$ post变量中,并使用页面参数添加指向同一页面的链接,即posts.php?page = 2。然后当page = 2时,阅读帖子11到20等等

相关问题