I have created views with display as page. In pager there is option to set no. of page to show. How can I set this dynamically by passing it through url? I can pass the page using ?page=2 and offset using ?offset=2 but I cant find a way to pass the no. of pages to show.

  • Are you talking about number of pages or number of items per page? – mpdonadio Feb 9 '12 at 15:01
  • no. of items to be skipped. I want it to be passed through url. – esafwan Feb 13 '12 at 13:57

I still don't quite get what you are asking about, but you should be able to examine $view->pager in a hook_views_pre_build and do what you want. For example, this is a snippet of code I have used in Drupal 6 and Views 2 to set the number of items per page:

function mymodule_views_pre_build (&$view)
    if ($_GET["perpage"]) {
        $perpage = check_plain($_GET["perpage"]);

        if (is_numeric($perpage) && (int) $perpage > 1) {
            $view->pager["items_per_page"] = (int) $perpage;
        } else if ($perpage == "all") {
            $view->pager["use_pager"] = false;
            $view->pager["items_per_page"] = 0;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.