Display number of rows in a Drupal View
How can I display the total number of rows sh开发者_Go百科own in a Drupal view as well as the number of rows out of the total currently being shown?
print $GLOBALS['current_view']->total_rows;
does not work
This question might be of help
$view->total_rows is wrong (sort of), I want "Items to display"
$view = views_get_view('MY_VIEW_NAME');
$view->set_display('MY_DISPLAY'); // like 'block_1'
$view->render();
print sizeof($view->result);
print sizeof($view->result);
does not work, because it returns the number of rows, not the number of total results. So if you have a pager, this doesn't work. You'll need
print $view->total_rows;
Another, even better solution would be to implement hook_views_pre_render()
function MYMODULE_views_pre_render(&$view) {
if ($view->name == 'MY_VIEW') {
$view->set_title(t('Search (@count results)', array('@count' => $view->total_rows > 0 ? $view->total_rows : 'No')));
}
}
精彩评论