function node_view_multiple

node_view_multiple($nodes, $view_mode = 'teaser', $weight = 0, $langcode = NULL)

Constructs a drupal_render() style array from an array of loaded nodes.

Parameters

$nodes: An array of nodes as returned by node_load_multiple().

$view_mode: View mode, e.g. 'full', 'teaser'...

$weight: An integer representing the weight of the first node in the list.

$langcode: (optional) A language code to use for rendering. Defaults to NULL which is the global content language of the current request.

Return value

An array in the format expected by drupal_render().

File

modules/node/node.module, line 2661
The core that allows content to be submitted to the site. Modules and scripts may programmatically submit nodes using the usual form API pattern.

Code

function node_view_multiple($nodes, $view_mode = 'teaser', $weight = 0, $langcode = NULL) {
  $build = array();
  $entities_by_view_mode = entity_view_mode_prepare('node', $nodes, $view_mode, $langcode);
  foreach ($entities_by_view_mode as $entity_view_mode => $entities) {
    field_attach_prepare_view('node', $entities, $entity_view_mode, $langcode);
    entity_prepare_view('node', $entities, $langcode);

    foreach ($entities as $entity) {
      $build['nodes'][$entity->nid] = node_view($entity, $entity_view_mode, $langcode);
    }
  }

  foreach ($nodes as $node) {
    $build['nodes'][$node->nid]['#weight'] = $weight;
    $weight++;
  }
  // Sort here, to preserve the input order of the entities that were passed to
  // this function.
  uasort($build['nodes'], 'element_sort');
  $build['nodes']['#sorted'] = TRUE;

  return $build;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/modules!node!node.module/function/node_view_multiple/7.x