Hello guys, im using views_embed_view() to embed a view on a node,
by default I set the view's items_per_page to 10, how do I limit the result being displayed on the view to 2 when it is being embed?

Comments

mooffie’s picture

The following code isn't tested, but it should work.

$view = views_get_view('the_view_name') or die('no such view');
$view->set_display('the_display_id');
$view->display_handler->set_option('items_per_page', 2);
print $view->preview(NULL, array('a', 'possible', 'array', 'of', 'arguments'));
Anonymous’s picture

Im going to test it now, hope this works on views 2. thanks man!

UPDATE:

Thanks man, it did work. is there also a way to check all the total rows returned?

mooffie’s picture

is there also a way to check all the total rows returned?

do print $view->total_rows. However, this number is calculated by default only if you're using a pager (because it isn't needed otherwise); to force calculating it, do $view->get_total_rows = TRUE early on.

Anonymous’s picture

wow cool! thanks a lot man. =)

DrupalDummy-1’s picture

Hi mooffie,

Thank you for your code.

I would like to print something after a text meesage after the pager in the first page of the view only. Here are the problems I faced.

1. When I used just the footer in view, it printed the message before the pager . Actually I want it after pager.

2. When I put the message in the last line of views-list-x.tpl.php page, the message is printed 10 times along with each item.

3. I tried to create a condition using the code you provided (for different purpose) to check whether it is the first page and whether it is the last item in the first page and then print my message. But I messed up everything. (I am not a programmer.)

How do I do this?

First Page of view

Display list of 10 items

Display Pager

My Message

Thanks a lot.

anou’s picture

...you just find finally what you need ! Thanks to you. Happy new year !!!

David THOMAS
http://www.smol.org