You are here

Displaying number of pages showing in pager for Drupal 7 views

For displaying showing of 1-1 in views is quite tricky.

You just need to create views tpl file. I take it that you know how to create a tpl file for view in drupal 7.

I am using the views-view--viewname.tpl.php, i have list style in my tpl file.

In your tpl file just add the below links whereever you want to display the number of pages showing.


<?php

global $pager_page_array, $pager_total, $pager_limits;

$from = ($view->query->pager->current_page * $view->query->pager->options['items_per_page']) + 1;

$to = $from + count($view->result) - 1;

$total = $view->total_rows;

if($total > 0){

if ($total <= $to) {

print 'Showing '.$total.''.$pager.'';

}

else

{

print 'Showing '.$from.' - '.$to.' out of '.$view->total_rows.''.$pager.'';

}

}

?>

In the above function there is if statement which is for displaying showing X amount of pages if the number of items are less.

If there are more than one page than the other part of the pager works.

For debugging print_r the global varriables to check whether you are getting the values or not.

$pager varriable displays the pager.

Website fix request form

If you have problems with the website based on Drupal or WordPress, please feel free to contact us: