You are here

function _prevnext_get_prevnext in Prevnext 7

Helper: Retrieve previous/next nodes

1 call to _prevnext_get_prevnext()
prevnext_node_view in ./prevnext.module
Implements hook_node_view().

File

./prevnext.module, line 130
prevnext.module

Code

function _prevnext_get_prevnext($node, $language = NULL) {
  $query = new EntityFieldQuery();
  $query
    ->entityCondition('entity_type', 'node')
    ->propertyCondition('type', $node->type)
    ->propertyCondition('status', 1);
  if (!is_null($language)) {
    $query
      ->propertyCondition('language', $language);
  }
  $result = $query
    ->execute();
  $nids = array();
  foreach ($result['node'] as $result_nids) {
    $nids[] = $result_nids->nid;
  }
  $key = array_search($node->nid, $nids);
  return array(
    'prev' => !empty($nids[$key - 1]) ? $nids[$key - 1] : '',
    'next' => !empty($nids[$key + 1]) ? $nids[$key + 1] : '',
  );
}