I have a given number of potential posts. We don’t know how many there are but the system is set up to show 12 per page. Along the bottom I would like it to display the number of pages.
So first if we get the posts:
<?php $pages = get_posts('category_name=news'); ?>
Now what we want to do is
- work out how many posts it has found
- divide that number by 12
- round that number up to the nearest whole number (UP never down)
- divide that number by 1 and give how many times 1 goes into it.
- thus giving as many page numbers as needed.
The ideas is to have them lined up as 1 | 2 | 3 | 4 | 5 etc..
Any ideas?
You’re over thinking it. If you know the number of results and the max number of results per page, then you know how many pages you need. I suppose this is WordPress because you’ve used get_posts, so that should return an array containing the posts, so: