我有一定数量的潜在职位.我们不知道有多少,但系统设置为每页显示12个.在底部我希望它显示页数.
首先,如果我们得到帖子:
<?php $pages = get_posts('category_name=news'); ?>
Run Code Online (Sandbox Code Playgroud)
现在我们想做的是
想法是将它们排成1 | 2 | 3 | 4 | 5等..
有任何想法吗?
Pho*_*nix 10
你在想它.如果您知道结果数量和每页的最大结果数,那么您就知道需要多少页面.我想这是WordPress,因为你使用了get_posts,所以应该返回一个包含帖子的数组,所以:
<?php
$max_per_page = 12; //Max results per page
$posts = get_posts('category_name=news');
$total_posts = count($posts); //Total number of posts returned
$pages = ceil($total_posts / $max_per_page);
for($i = 1;$i <= $pages;$i++)
{
echo '<a href="?page=' . $i . '">' . $i . '</a>'; //Or whatever the link needs to be
if($i != $pages)
{
echo "|"
}
}
?>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13057 次 |
| 最近记录: |