Drupal multiple Views on same page

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

Related posts:

  1. Drupal 6.x Why do I see candidate function names and not candidate template files?
  2. Drupal Clear Top ‘page not found’ errors – How to?
  3. Drupal Change Publishing options
  4. “defizet” This is a test word to see how quickly this page gets indexed by Google
  5. Drupal – The selected file… could not be uploaded. Only JPEG, PNG and GIF images are allowed
  6. “Increase Google Page Rank” It’s official – I now hate Google.
  7. Access denied – Drupal 6.x


2 Comments

  1. Comments  Sasha   |  Monday, 10 May 2010 at 3:51 pm

    Thank you very much! That was extremely simple and very very useful!

  2. Comments  Tejas Sali   |  Tuesday, 03 May 2011 at 9:19 am

    Thanks, that’s exactly what I was looking for.

Leave a Reply