Pagination + categorisation

Hi,

In my controller I have:

 $items = $page->children()->listed()->paginate(12);
// add the categories filter
  if($category = param('category')) {
    //Used for multiple words categories
    $category = urldecode(param('category'));    
    $items = $items->filterBy('cat', $category, ',');
  }
$categories = $items->pluck('cat', ',', true);

It shows all categories in the parent page and when is clicked, filter and show correspondant subpages. All work correctly.

Now I try to use the pagination the same way as in the cookbook pagination with link for each page.

The issue is that, if I go to the page 3 or 4 etc… and filter content with a category, it will show only results witch exist in the first pagination page.

Am I doing something wrong or missing something?

Thx

Pagination must take place after your filtering:

 $items = $page->children()->listed();
// add the categories filter
  if($category = param('category')) {
    //Used for multiple words categories
    $category = urldecode(param('category'));    
    $items = $items->filterBy('cat', $category, ',');
  }

$items      = $items->paginate(12);
$pagination = $items->pagination();
$categories = $items->pluck('cat', ',', true);
1 Like

Thank you Sonja