There is a page on a site I'm building that is going to have a View embedded four times, each time with a different argument. Basically, I'm showing the latest post for four different categories that the posts are organized into.

I want each embedded View to show one post at a time and use AJAX pagers to allow users to page to the next-oldest post in a particular category right there on that page. Of course, the following code doesn't work because pager_element is set to 0 for each of them.

 print views_embed_view('principles', 'embed', 'access');
print views_embed_view('principles', 'embed', 'choice');
print views_embed_view('principles', 'embed', 'openness');
print views_embed_view('principles', 'embed', 'innovation'); 

If I manage to set pager_element for these from 0-3, would that make all the pagers work, even though they are all on one page?

I've been trying to do this, but I don't really know my way around setting options for a View and then rendering it. With the following code, the View renders all of the results without a pager, rather than the one at a time with a pager. Any guidance on how to set pager_element so that each of these embedded views along with their AJAX pagers work would be greatly appreciated!

 $innovation = views_get_view('principles');
$innovation->set_display('default');
$innovation->set_arguments(array('innovation'));
$innovation->display['default']->display_options['pager_element'] = 5;
$innovation = $innovation->render();
print $innovation;

Thanks.

Comments

akahn’s picture

Alright, so I've found that I can't use 'embed' as the display id, it has to be 'page_2'. That makes some stuff work better. But I'm still having an issue where when I print the view using $innovation->render(), for example, all of the results get spit out, rather than just 1, like it is set to, with a pager. Why is this? Also, how come print $innovation->preview() doesn't output anything? I'm sort of following panels_views.module as a model for how to set options and print the view, but not having much luck.

merlinofchaos’s picture

The options for the pager get copied from the display to the view during pre_execute(). If you are not using preview() or execute_display() you must be sure to run pre_execute().

domesticat’s picture

Status: Active » Closed (fixed)

Closed while closing all Views support requests with no activity for 6 months. If you still need help, you may re-open this issue at any time.