Drupal is a fairly flexible system as far as CMS applications go, and is even more flexible as a development platform. The Views module gives developers ways to dynamically build queries of data, and display that data in many different ways. Sometimes, however, you want to display views in ways not supported through the admin interface. Fortunately, there are other ways to get the job done.
For example, I have a block in my sidebar where I want to display a list of the latest blog post, latest forum topic, and latest user poll. Each of these lists can be created as separate views. However, there doesn't seem to be any functionality, either in the Views module or another third-party module, that allows you to display multiple unrelated views in a single block. So, we turn to the code. The Views API provides a mechanism for building and displaying your views anywhere in your templates:
<?php views_get_view($name_of_view); ?>
<?php views_build_view($type, $view, $view_args, $use_pager, $node_limit); ?>
Back to my example - I simply created a new block, and set the input format to PHP. Then, I used the following code to populate the block with the views:
<h2>Latest Blog Post:</h2>
<?php echo views_build_view('embed', views_get_view('latest_blogpost'), null, false, 1); ?>
<h2>Latest Forum Topic:</h2>
<?php echo views_build_view('embed', views_get_view('latest_forumtopic'), null, false, 1); ?>
<?php echo views_build_view('embed', views_get_view('latest_userpoll'), null, false, 1); ?>
The above code shows the rendered view. However, there are times where you want or need to do some additional processing on the values returned by the view. Fortunately, the Views module is incredibly powerful, and has a ton of options for retrieving the views.
In the above example, the first argument to the views_build_view() function is 'embed'. There are several other options:
This information comes directly from the code, and hopefully, it will be of some assistance to people who are looking for this kind of functionality.
[tags]block, cms, development, drupal, php, templates, Views[/tags]