Showing posts with label views. Show all posts
Showing posts with label views. Show all posts

Friday, July 12, 2013

Alter view and pager to display more items per page programmatically

I have 1 codebase for a multisite install. I needed to change the number of items per page on every page and didn't want to use the view ui and change every view. So I looked for a way to do this programmatically.

As it turns out this is quite simple.

I used hook_views_pre_build() to do this:

/**
 * Implements hook_views_pre_build ()
 */
function MODULENAME_views_pre_build(&$view) {
  if($view->name == "name_of_your_view") {
    $view->items_per_page = 30;
  }
}