Last updated 15 August 2011. Created on 28 July 2011.
Edited by kaido24. Log in to edit this page.

This code will give the users a capablity to choose, how many elements(items) they can display on the views page. Just create a module and configure array values and its done. The code uses the views header section to display the number selection menu.
View name is the name of the currently opened view.
You will find your page id at the end of your view url, right next to views-tab-, after you have opened your current tab in the new window. This will look something like that: admin/build/views/edit/youre_view_name#views-tab-page_id .

function modulename_views_pre_execute( &$view ) {

	#Configuration start

	# set array values view_name => page_id
	$views_data = array(
		'newest_books'	=> 'page_1',
		'bestprice'		=> 'page_1',
		'taxonomy_term'	=> 'page',

	#Set number of items to show
	$numbers_to_show = array(5 ,25 ,100);
	#Configuration end

	$page_id = $views_data[ $view->name ];
	if( ! $page_id ) { return; }

	$view_url_path = $view->display[$page_id]->display_options['path'];
	$vupc = strlen($view_url_path);
	$page_path = substr($_GET['q'] , 0, $vupc);
	if( $page_path != $view_url_path ) { return; }
	# Create links
	$items_per_page = array();
	foreach( $numbers_to_show as $nr ) {
		$items_per_page[] = l( $nr, $_GET['q'], array( 'query' => "items=$nr" ) );
	$header = t('Items per page') . ': ' . implode( ' | ', $items_per_page );

	# hack the view
	$default_count = $view->display[$page_id]->handler->default_display->options['items_per_page'];
	$selected_count = $_GET['items'];
	$handler = &$view->display[$page_id]->handler;
	$handler->set_option('header', $header);
	$handler->set_option('header_format', 2);	

	# set items per page
	$view->set_items_per_page( $_GET['items'] > 0 ? $selected_count : $default_count );


Looking for support? Visit the forums, or join #drupal-support in IRC.


FranckV’s picture

Using this hook does the job as far as the number of items displayed per page... but kills my exposed filters selection : instead of having e.g. exposed filters dropboxes containing values corresponding to all the pages, the dropboxes only contain the values corresponding to the visible items of the current page... that's a shame.

Any idea why ?