Embed Drupal Views Using PHP
When theming Drupal and wanting to output a view there are occasions where using a view display (e.g. a page, or a block - perhaps placed within a custom region ;-) ), or using Views Attach will not suffice.
Instead, you can embed a view using the following PHP snippet:
(NOTE: you'll need to have the core PHP input filter enabled if embedding in a node body)
<span style="color: #000000"><span style="color: #0000BB"><?php<br>$view </span><span style="color: #007700">= </span><span style="color: #0000BB">views_get_view</span><span style="color: #007700">(</span><span style="color: #DD0000">'VIEWNAME'</span><span style="color: #007700">);<br>print </span><span style="color: #0000BB">$view</span><span style="color: #007700">-></span><span style="color: #0000BB">preview</span><span style="color: #007700">(</span><span style="color: #DD0000">'default'</span><span style="color: #007700">);<br></span><span style="color: #0000BB">?></span></span>
or, if you need to use an argument with the view:
<span style="color: #000000"><span style="color: #0000BB"><?php<br>$args </span><span style="color: #007700">= array(</span><span style="color: #0000BB">ARGUMENTS</span><span style="color: #007700">);<br></span><span style="color: #0000BB">$view </span><span style="color: #007700">= </span><span style="color: #0000BB">views_get_view</span><span style="color: #007700">(</span><span style="color: #DD0000">'VIEWNAME'</span><span style="color: #007700">);<br>print </span><span style="color: #0000BB">$view</span><span style="color: #007700">-></span><span style="color: #0000BB">preview</span><span style="color: #007700">(</span><span style="color: #DD0000">'default'</span><span style="color: #007700">, </span><span style="color: #0000BB">$args</span><span style="color: #007700">);<br></span><span style="color: #0000BB">?></span></span>