Last Updated: February 25, 2016
·
602
· sanguis

Replace views with efq for site speed and ease of export.

Views is slow, and a PIA to export.
Bellow is a basic page that can be copied and used to display a list of nodes.

<?php
/**
 * Implements hook_menu().
 */
function team_menu() {
  $items['team'] = array(
    'title' => t('Team'),
    'page callback' => 'team_page',
    'access arguments' => array('access content'),
    'type' => MENU_NORMAL_ITEM,
  );

  return $items;
}

function team_page() {
  $query = new EntityFieldQuery();
  $query
    ->entityCondition('entity_type', 'node')  //entity type
    ->propertyCondition('status', 1) //published
    ->entityCondition('bundle', 'team') //node type
    ;
  $result = $query->execute();
  if (count($result) > 0) {
    $nids = array_keys($result['node']);
    $output = node_view_multiple(node_load_multiple($nids), 'teaser');
  }
  else { //if there are no nodes of that type
    $output['#prefix'] = "<h2>" . t('Not Found') . "</h2><p>" . t('No team members found') . "</p>";
  }
  return $output;
}