How to Programmatically Insert a View into a Drupal 6 Node

[NOTE: This post was originally published in the old blog on May 18, 2010.]

Inserting a Drupal 6 view into a node or template file with PHP is easy. Just use the code below:

$viewName = 'the_name_of_my_view';
$display_id = 'block_1';
print views_embed_view($viewName, $display_id);

The $viewName and $display_id can be found by exporting your view. The $display_id is the third argument of new_display:

$handler = $view->new_display('block', 'Block', 'block_1');

(PHP tags added in the last example above only to colorize the code.)

Related posts:

Leave a Reply

Your email address will not be published. Required fields are marked *