Community Documentation

Displaying an item count under a view listing

Last updated April 20, 2011. Created by dman on April 20, 2011.
Log in to edit this page.

If using the pager, that can display an indication of the number of items. But it you want an all-in-one list, it's often handy to have a sum at the bottom.

Use a PHP snippet

If you are happy to open up php format, edit your view and insert this code from faost

<?php
$current_view
= views_get_current_view();
print
count($current_view->result);
?>

into the footer area.

Do it in one of your own modules

If you prefer to keep code in the modules, and not use PHP format in the UI, try something like this

<?php
/**
* HOOK_views_pre_render()
* When rendering one of our own views, insert a count into the footer.
*/
function MODULENAME_views_pre_render(&$view) {
 
$view->style_plugin->display->handler->options['footer'] = count($view->result) . " items";
 
$view->style_plugin->display->handler->options['defaults']['footer'] = FALSE;

}
?>

Special modules

There are a couple of modules built to handle this also. It may be excessive to enable a whole module for something that can be done in such a small snippet, but:
views_calc Seems worth it

Page status

No known problems

Log in to edit this page

About this page

Drupal version
Drupal 6.x
Audience
Developers and coders

Reference

Drupal’s online documentation is © 2000-2012 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.