Skip to content

Instantly share code, notes, and snippets.

@esafwan
Last active December 22, 2015 13:29
Show Gist options
  • Save esafwan/6479466 to your computer and use it in GitHub Desktop.
Save esafwan/6479466 to your computer and use it in GitHub Desktop.
Load view and then set its display, limit how much to load, pass argument and then render all programatically. Easy snippet or example code.
<?php
//Load the view.
$view = views_get_view('news_master');
//set the display.
$view->set_display('block');
//set the limit.
$view->set_items_per_page(8);
//set offset
$view->set_offset(5);
//pass the arguments.
$view->set_arguments(array($tid));
//setting the page, so that its show.
$pager = $view->display_handler->get_option('pager');
$pager['type'] = 'mini'; //or 'full'
$view->display_handler->set_option('pager', $pager);
//compulsory if you want the cache & all to work.
$view->pre_execute();
//execute everything.
$view->execute();
//render the final output
$content = $view->render();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment