Last active
October 7, 2015 02:27
-
-
Save mynameispj/3090398 to your computer and use it in GitHub Desktop.
Next / previous node links in Drupal 7
This file contains 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
switch($n_node->type) { | |
case 'your-custom-content-type-machine-name-here': | |
$html = l('"'.$n_node->title .'"', 'node/'.$n_node->nid, array('html' => TRUE, 'attributes' => array('class' => array('prev-next'), 'title' => $n_node->title))); | |
return $html; | |
} |
This file contains 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
switch($n_node->type) { | |
case 'your-custom-content-type-machine-name-here': | |
$html = l('"'.$n_node->title .'"', 'node/'.$n_node->nid); | |
return $html; | |
} |
This file contains 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 | |
$nextPost = pn_node($node, 'n'); | |
$prevPost = pn_node($node, 'p'); | |
if ($nextPost != NULL) { ?> | |
<?php print $nextPost; ?> | |
<?php } ?> | |
<?php if ($prevPost != NULL) { ?> | |
<?php print $prevPost; ?> | |
<?php } ?> |
This file contains 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
<ul> | |
<li><?php print pn_node($node, 'n'); ?></li> | |
<li><?php print pn_node($node, 'p'); ?></li> | |
</ul> |
This file contains 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 pn_node($node, $mode = 'n') { | |
if (!function_exists('prev_next_nid')) { | |
return NULL; | |
} | |
switch($mode) { | |
case 'p': | |
$n_nid = prev_next_nid($node->nid, 'prev'); | |
$link_text = 'previous'; | |
break; | |
case 'n': | |
$n_nid = prev_next_nid($node->nid, 'next'); | |
$link_text = 'next'; | |
break; | |
default: | |
return NULL; | |
} | |
if ($n_nid) { | |
$n_node = node_load($n_nid); | |
switch($n_node->type) { | |
case 'article': | |
$options = array('absolute' => TRUE); | |
$nid = $n_node->nid; | |
$url = url('node/' . $nid, $options); | |
$html = '<a class="button" href="'. $url .'" />' . $n_node->title . '</a>'; | |
return $html; | |
} | |
} | |
} |
This file contains 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 pn_node($node, $mode = 'n') { | |
if (!function_exists('prev_next_nid')) { | |
return NULL; | |
} | |
switch($mode) { | |
case 'p': | |
$n_nid = prev_next_nid($node->nid, 'prev'); | |
$link_text = 'previous'; | |
break; | |
case 'n': | |
$n_nid = prev_next_nid($node->nid, 'next'); | |
$link_text = 'next'; | |
break; | |
default: | |
return NULL; | |
} | |
if ($n_nid) { | |
$n_node = node_load($n_nid); | |
switch($n_node->type) { | |
case 'article': | |
$html = l('"'.$n_node->title .'"', 'node/'.$n_node->nid); | |
return $html; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment