Limit SimpleSearch Pagination to 10 pages at a time?

Is there a way to limit the SimpleSearch pagination to 10 pages at a time with a prev and next button on the ends?

Pagination (with a page size of 10) should be enabled by default. A different page size can be set with the property perPage.

[[!SimpleSearch? &perPage=`10`]]
1 Like

Not the results per page, but 10 pages of results, at a time. With more coming into view as the user progresses.

So something like the way Google search works:

Instead of the unlimited set of pages that SimpleSearch returns:

Sorry, I misread your question.

There is some functionality like this in the code, but I found no documentation, so I’m not quite sure how to use it (or if it even works).

[[!SimpleSearch? &pageLimit=`10` &pageFirstTpl=`PageLink` &pagePrevTpl=`PageLink` &pageNextTpl=`PageLink` &pageLastTpl=`PageLink`]]

pageLimit = The maximum number of page links to display when rendering page navigation controls.
pagePrevTpl = The chunk to use for the previous page pagination link.
pageNextTpl = The chunk to use for the next page pagination link.

It looks like those features have a bug, where it will show 10 pages starting out and then add more until you have 10 on either side of the current page. So when you start out on page 1 you see pages 1 through 10. Then as you move up it adds more until you reach 10 on either side.

So close, but not quite there.

The only way to get the desired output, is to change the code yourself. I gave it a try and the following code may or may not work (the getPagination function is kind of a mess).
Replace this line in the original code with this code:

$pageLimitBelow = floor(($pageLimit - 1) / 2);
$pageLimitAbove = $pageLimit - 1 - $pageLimitBelow;

$currentPage = floor($currentOffset / $perPage);
if ($currentPage < $pageLimitBelow){
	$pageLimitBelow = $currentPage;
	$pageLimitAbove = $pageLimit - 1 - $pageLimitBelow;

if (($pageLinkCount - 1 - $currentPage) < $pageLimitAbove){
	$pageLimitAbove = ($pageLinkCount - 1 - $currentPage);
	$pageLimitBelow = $pageLimit - 1 - $pageLimitAbove;

if (empty($pageLimit) || ((int)$pageArray['offset'] >= $currentOffset - ($pageLimitBelow * $perPage) && (int)$pageArray['offset'] <= $currentOffset + ($pageLimitAbove * $perPage))){

Be aware that when you change the code, the changes will be lost the next time you update the extra!

As far as I can tell that fix is working like expected.

Maybe that code could be integrated into the next release. I can’t imagine it currently works the way the developers intend. I created an issue pointing to this thread.

This topic was automatically closed 2 days after discussion ended and a solution was marked. New replies are no longer allowed. You can open a new topic by clicking the link icon below the original post or solution and selecting “+ New Topic”.