Last active
December 31, 2015 02:09
-
-
Save micahredding/7919178 to your computer and use it in GitHub Desktop.
Next and Previous Nodes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php if($next_node): ?> | |
<a href="node/<?php print $next_node; ?>">Next Node</a> | |
<?php endif; ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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