views:

25

answers:

2

The "total_rows" property of my view returns the total rows (22), but not the number of items I have set the view to display (5) (through the Web UI Block->Basic Settings).

How can I get this in a proper way without relying on (the possibly soon to be deprecated "result" property?

for now Im using $totalRows = min($view->total_rows, count($view->result));

A: 

Does $view->pager["items_per_page"] fit your needs? I am not 100% sure when this is available, but I am using it in a hook_views_pre_build() in a custom module.

MPD
This only works if you are using a pager. If you are limiting the number of rows in the view but NOT using a pager, this parameter will not be set.
theunraveler
Thanks for the clarification. The custom module I mentioned was mucking around with this value to implement a "results per page" feature for a paged view.
MPD
+1  A: 

This is always available as:

$view->display['your_display']->display_options['items_per_page']

where your_display is replaced by the views display you are using (e.g. page_1, block_1, etc). This is available at all stages of building process.

theunraveler

related questions