Skip to content

Instantly share code, notes, and snippets.

@micahredding
Last active December 31, 2015 02:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save micahredding/7919178 to your computer and use it in GitHub Desktop.
Save micahredding/7919178 to your computer and use it in GitHub Desktop.
Next and Previous Nodes
<?php if($next_node): ?>
<a href="node/<?php print $next_node; ?>">Next Node</a>
<?php endif; ?>
function hook_preprocess_page(&$variables, $hook) {
if(arg(0) == 'node' && is_numeric(arg(1)) && $node = node_load(arg(1)) {
if($node->type == 'case_study') {
$query = new EntityFieldQuery();
$entities = $query->entityCondition('entity_type', 'node')
->entityCondition('bundle', 'case_study')
->propertyCondition('status', 1)
->propertyOrderBy('nid', 'ASC')
->execute();
$nodes = node_load_multiple(array_keys($entities['node']));
if(count($nodes) > 0) {
$next_node = reset($nodes);
}
$variables['current_node'] = $node->nid;
$variables['next_node'] = $next_node->nid;
$variables['prev_node'] = $node->nid - 1;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment