If you’re using Drupal 6.x and you need to display multiple ‘Views’ on your homepage (or any other page for that matter) here’s the code that will do it for you…

In this example I will be displaying the View called ‘showcase’, just change it to whatever name you called your View. The only text you need to change is highlited in red.

You can paste this code into your page.tpl.php file for as many Views as you need!

<?php
    $viewname = 'showcase';
    $display_id = 'showcase'; // or any other display
    $args = array();
    $args [0] = 'foo'; // These values are optional
    $args [1] = 'bar';

    $view = views_get_view($viewname);
    $view->set_display($display_id);
    $view->set_arguments($args);
    print $view->preview();
?>

If you just want to display a View without passing in any variables (args) then you can simply have:

<?php
    $viewname = 'showcase';
    $display_id = 'showcase'; // or any other display
    $view = views_get_view($viewname);
    $view->set_display($display_id);
    print $view->preview();
?>

Boom! Job done.

All the best

Simon

2 comments

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>