I have created some views and I know that you can use this code to embed a view:

$view = views_get_view('view_name');

My question is how to embed many views into one page.

Can I do this:

$view = views_get_view('view_name');
$view = views_get_view('view_name');

thanks in advance.

Comments

dww’s picture

Fetching the view object doesn't display it. Depending on 5.x or 6.x, the function you invoke on that $view object is different.

5.x:

$output = '';
$view1 = views_get_view('view_1_name');
$view_type = 'page'; // or whatever
$args = array('foo', 'bar') // if your view needs arguments
$output .= views_build_view($view_type, $view1, $args);
$view2 = views_get_view('view_2_name');
$args = array('baz')
$output .= views_build_view($view_type, $view2, $args);
echo $output;  // or maybe return($output) depending on what context

6.x:

$output = '';
$view1 = views_get_view('view_1_name');
$view_display = 'page1'; // or whatever Views2 display you want
$args = array('foo', 'bar') // if your view needs arguments
$output .= $view->preview($view_display, $args);
$view2 = views_get_view('view_2_name');
$view_display = 'block1';
$args = array('baz')
$output .= $view->preview($view_display, $args);
echo $output;  // or maybe return($output) depending on what context

___________________
3281d Consulting

dww’s picture

Or, you can use http://drupal.org/project/viewfield to embed views as CCK fields on your story nodes. There are a bunch of ways to do this...

___________________
3281d Consulting