Jump to content

Keeping order of page IDs in pagearray


alexcapes
 Share

Recommended Posts

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?

 

 

 

Link to comment
Share on other sites

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?

 

 

 

 

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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
 Share

×
×
  • Create New...