Pedro Posada | Embed VIEWS 2 into nodes

Embed VIEWS 2 into nodes

Posted on March 25, 2009 - 5:02pm
<< 23 of 54 >>

Very useful lines of code to embed "Views 2" views into your nodes.

Works almost as the old

<?php
$view
= views_get_view('views_name');
print (
views_build_view('embed', &$view, array(), $view->use_pager, $view->nodes_per_block));
?>

in Drupal 5 but for Drupal 6. This is also a way to embed views programatically into your pages and nodes.

The following lines of code will load a view and print the display.

<?php
$view
= views_get_view($viewname);
$view->set_arguments( array( $arg ) );
$view->set_display($displayId);
$view->set_items_per_page($number);
$view->execute();
$count = count( $view->result );
print
$view->preview($display_id, $args);
?>

The following line will print the output of a view. You can pass it the display name to show any display you want. And also the arguments if any.

<?php
print views_embed_view($viewname, $display_id = 'default', $arg1, $arg2);
?>

Note:
To dynamically filter the view

<?php

$view
= views_get_view('name_of_view');
$view->set_display('name_of_display');
$filter = $view->get_item('name_of_display', 'filter', 'name_of_filter');
$filter['value'] = 'some value';
$view->set_item('name_of_display', 'filter', 'name_of_filter', $filter);
$view->set_items_per_page(3);
$view->execute();

print_r($view->result);

?>

Here is a very nice article about it http://api.freestylesystems.co.uk/api/function/views_embed_view/6

Another good source for manipulating and embedding your views 2 http://thedrupalblog.com/category/tags/set-display

Another good resource http://views2.logrus.com/doc/html/classview.html#d1f69acfdb3771ec2d6f54f... Not the easiest to understand though

Submitted by jerabelle (not verified) on March 20, 2011 - 7:14pm.

Thanks for all the enthusiasm of posting good article with good ideas. It’s very useful. Check for more information at www.mgupload.net to enrich your knowledge about hormones

Jerabelle
www.mgupload.net

Submitted by Your online Library (not verified) on August 15, 2011 - 11:51pm.

I’m impressed. Very informative and trustworthy blog does exactly what it sets out to do. I’ll bookmark your weblog for future use.

Joseph
www.joeydavila.com
Your online Library

Post new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Copy the characters (respecting upper/lower case) from the image.