March 16, 2011
Showing total number of items in a view
Wow. What. A. P.I.T.A.
All I want to do is add a header to a View that says the following:
You are viewing [numItems] of [totalItems] records.
and it is nigh impossible.
$view = views_get_current_view();
$items_displayed = $view->pager['items_per_page'];
$num_rows = $view->total_rows;
You are viewing < ?php print $items_displayed; ?> of < ?php print $num_rows; ?> records.
and you get what you are asking for.
[Not so fast Mister and Miss Opensource...]
If you are limiting the number of items to display, then you need to have a Pager on your view. Problem solved.
[There you go again...]
If your view takes an argument a collision between Drupal Core and Views causes the pager not to render and your total row count is always 1. You might think adjusting the offset would work, but noooo.
[But wait, simple, simpletons...]
The cause of your problem isn't actually the pager, it is the use of distinct in Core which returns a count of 1 which is the problem you were experiencing in the first place.
[Oh yeah. It gets better...]
While having an NID argument can cause the problem, so can having Content Access and/or ACL enabled.
Posted by kkwaiser at March 16, 2011 12:04 PM