Is there a way to pass the number of items to display per page as argument to an embed view by code?
I used to do that with Views 1 in this way:

$view = views_get_view('hpTab1NonFeatured');
print views_build_view('embed', $view, null, false, 2);

where 2 were the number of items to display.
Now i have this code in Views 2:

$args = array();
$v = views_get_view('moreNews');
echo $v->execute_display('default', $args);

I don't know where i can pass that argument. Is there a way?

Thanks in advance!

Matias.

Comments

merlinofchaos’s picture

You can do this:

  $v = views_get_view('viewname');
  $v->init_display('default');
  $v->display_handler->set_option('items_per_page', $count);
  $v->execute_display();

Note that I generally prefer adding additional displays if you want to change options, since you can easily select an alternate display. Though I guess I don't have any extra 'do nothing' displays so you'd probably have to add block displays. And with those you don't actually want to use $v->execute_display(), you want to use $v->preview() (because execute_display will return a block object suitable for hook_block()).

merlinofchaos’s picture

Status: Active » Fixed
mburak’s picture

It's showing nothing with that code that you suggested. Are you or me missing something? The view result seems to be empty.

mburak’s picture

Nevermind, i missed the 'echo' before the $v->execute_display();

Thanks!!

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

Dimm’s picture

$myview->display['block_3']->handler->options['items_per_page']=47;
alienzed’s picture

None of those suggestions work for me... has this changed again?
All I want to do is load and render a view from within a drupal 'Page' and set the items per page manually.
my ultimate goal is to allow the user to select his/her prefered items per page count, hold that data in a session variable and load it into each view for setting the items per page...
but I can't figure out how to programmatically set the items_per_page...

haleagar’s picture

see http://drupal.org/node/404714

$view->set_items_per_page($number);

giorgio79’s picture

Is there a way to use this as a URL argument?