You are here

function _node_gallery_views_embed_view in Node Gallery 6.3

Produces the output of a view just like views_embed_view() but increments pager ids each time this is called so when more than one NG view's are displayed on the same page, the pager ids do not interfeare with each other.

@staticvar int $pager_id Static counter for views pagers.

Parameters

string $name Identifier of the view to instantiate.:

string $display_id Identifier of the views display to use.:

1 call to _node_gallery_views_embed_view()
_node_gallery_gallery_view in ./node_gallery.module
Attaches the gallery node's image view to the node's content.

File

./node_gallery.module, line 1270
Node gallery module file.

Code

function _node_gallery_views_embed_view($name, $display_id = 'default') {
  static $pager_id = 0;
  $args = func_get_args();
  array_shift($args);

  // remove $name
  if (count($args)) {
    array_shift($args);

    // remove $display_id
  }
  $view = views_get_view($name);
  if (!$view || !$view
    ->access($display_id)) {
    return;
  }

  // Override view pager options here
  if (method_exists($view, 'init_pager')) {

    // Views 3 version
    $pager = $view->display_handler
      ->get_option('pager');
    $pager['options']['id'] = ++$pager_id;
    $view->display_handler
      ->set_option('pager', $pager);
  }
  else {
    $view
      ->set_display($display_id);
    $view->display_handler
      ->set_option('pager_element', ++$pager_id);
  }
  return $view
    ->preview($display_id, $args);
}