Jump to content

2 pagers on a single template


antpre
 Share

Recommended Posts

Hello everyone,

Is it possible to use 2 pagers to paginate 2 differents lists of pages (for example 1 news list and 1 blog post list) on one single template. I have tried it and it seems that the two pagers interfer with each other. For example if both the pagers are on n°1. if I click on the link to go to pagination 3 of the news list pager. When the page reloads then the the pager of the news list is on pagination 3 - thats ok- but the pager of blog post list has also shifted to pagination 3 -that's not ok- and vice versa (if I user the pager of the other list it afects the display of the first list).
Is it a normal behavior ... Or maybe I am juste doing it wrong ???

Thanks in advance

Link to comment
Share on other sites

You can render two independent paginations, but only use one at a time. You'd use the getVars option or $input->whitelist() (if you need some filter values to be populated as well) to add a kinda "switch" GET variable, which tells you which pagination is currently used. When you know which pagination was clicked you can manually set the "start=" part to only the selector of the clicked pagination. There's no automated way to differenciate multiple paginations. 

  • Like 1
Link to comment
Share on other sites

OK done. It's working.

As you mentionned, I passed a variable to know which pager was clicked and I added a condition before each of the selectors so that when the pager of the other selector was clicked that pager sticks to the first pagination.

Thanks a lot

Link to comment
Share on other sites

I just copied the parts I used to one piece. You could also use different GET variables, but keep in mind to unset these again after rendering a single pagination.

public function pageStart($limit){
  $limit = (int) $limit;
  if(wire('input')->pageNum === 1 || $limit < 1){
    return 0;
  }

  return (wire('input')->pageNum - 1) * $limit;
}

$pa = $pages->find("…, limit=15, start=".(!$input->get->second ? pageStart(15) : 0);
$pa2 = $pages->find("…, limit=15, start=".($input->get->second ? pageStart(15) : 0);

$pagination = $pa->renderPager();
$input->whitelist("second", 1);
$pagination2 = $pa2->renderPager();
  • Like 1
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...