Jump to content

Recommended Posts

Posted

Hi there!

To allow something as simple as pagination with a little help of $_GET and math.

With an additional selector offset, you should be able to get pagination easily done without extra modules.

$limit = 10;
$offset = $limit * $_GET['page'] - $limit; // page 1 = offset 0, page 2 = offset 10
$posts = $pages->find('template=news, sort=-created, offset='.$offset.' limit='.$limit);

So far so good. The only thing missing is the markup:

<div class="pagination">
<?php
	$pagination = $_SERVER["REQUEST_URI"].'?page=';
?>
	<a href="<?=$pagination.'1'?>">First</a>
	<!-- numbers -->
	<?php
		$amount = count($pages->find('template=news'));
		while ($i = 1; $i < $amount / $limit; $i ++ {
	?>
		<a href="<?=$pagination.$_GET['page']+$i?>"><?=$i + ($offset / $limit) // 1 + 10/10 = 2 ?></a>
	<?php } ?>
	<a href="<?=$pagination.$amount?>">Last</a>
</div>

Kept very simple so far. But this is only one good example of how to use the offset selector.

If there is already something like that implemented, I'd be glad to hear from it!

Thanks in advance.

Cheers,

Martin Muzatko

Posted

There is start?

$posts = $pages->find('template=news, sort=-created, start=80, limit=40');

Thank you a lot!

My wish seems to be already built in then. Thanks for pointing me there, I wasn't quite aware of it.

In that case, this thread can be closed.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...