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
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
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