Jump to content

Recommended Posts

Posted

Hi,

I have an array of Page IDs ($matches) which I'm using in a PageArray ($matches_limit):

$matches_limit = $pages->find("id=$matches, limit=$page_limit");

This is working fine but I need to maintain the sort order of $matches, however $matches_limit reorders the $matches (I guess to sort=sort).

Is it possible somehow to maintain the order $matches when outputted in the pagearray?

 

 

 

Posted
4 minutes ago, LostKobrakai said:

$matches->slice(0, $limit);

 

 

Thanks LostKobrakai, that works!

However I do need to paginate the results and using slice() breaks the Processwire pagination.

Any ideas on how pagination can work with a solution?

 

 

 

 

Posted
$matches->setStart($input->pageNum * $limit);
$matches->setTotal($matches->count);
$matches->setLimit($limit);
$matches = $matches->slice(0, $limit);
  • Like 5
Posted

Amazing!

I got there with some minor updates to LostKobrakai's code...

	$start_val = (($input->pageNum * $limit) - $limit);

        $matches->setStart($start_val);
        $matches->setTotal($matches->count);
        $matches->setLimit($limit);

        $matches_limit = $matches->slice($start_val, $limit);

Created a variable $start_val for the start value and updated the sum to -$limit value.

I created a variable called $matches_limit for displaying the search results, as I can't put slice() into the pagination renderPager().

The slice() uses the $start_val to correctly get the pages for each paginated results page too.

Thanks as always LostKobrakai.

 

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...