Basic Settings)." />
开发者

$view->total_rows is wrong (sort of), I want "Items to display"

开发者 https://www.devze.com 2023-01-20 18:14 出处:网络
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).

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开发者_Go百科($view->result));


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.


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.


By default the the result is rendered for the "default" display. If you want it for a particular display then you can use

$view = views_get_view('MY_VIEW_NAME');    

$view->set_display('MY_DISPLAY'); // like 'block_1'    

$view->render();   

print sizeof($view->result);


Here is a good solution that allows to display the total results (works with and without a pager) and also, the number of results on a current page (for example, on page 2 of 10): http://www.midwesternmac.com/blogs/jeff-geerling/views-show-showing-x-x-x

Be warned that this solution doesn't work for block type display, only for a page.

0

精彩评论

暂无评论...
验证码 换一张
取 消