Pagers
renee - March 30, 2009 - 19:37
| Project: | Node Hierarchy |
| Version: | 6.x-1.x-dev |
| Component: | User interface |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Jump to:
Description
Hi! I'd love for this module to have pagers that point to previous-up-next like in book. I've tried using custom pagers and a view, but it's kind of sketchy and it doesn't understand parents. But maybe somebody who knows more PHP than me could take a crack at it? At first glance it doesn't seem tooo hard :)

#1
I had the same probleme here. As you say, it couldn't have been to hard since the module already avails of a function ( nodehierarchy_get_children() ) which retrieves the children of a given node. Also, for getting the parent of a child could not be any simpler: just use $node->parent.
Anyway, this is the code I quickly put together. Take it as it is, but it should function. At the moment, I have this code in the template for my child content type (page-article.tpl.php). I dropped it in the content_bottom region. I'd be curious to know if block are "node-aware"... if they are then you could place this code in a block too.
<div id="content-bottom">
<?php
$nodes_list_array = nodehierarchy_get_children($node->parent);
//print_r($nodes_list_array);
while ($this_node = current($nodes_list_array)) {
if ($this_node == $node->nid) {
//echo 'The current node\'s position within the array of children is: '.key($nodes_list_array).'<br />';
$curr_pos = key($nodes_list_array);
}
next($nodes_list_array);
}
$prev_key = $nodes_list_array[$curr_pos - 1]; // Get the child before the current
$next_key = $nodes_list_array[$curr_pos + 1]; // Get the child after the current
//Output starts
$output = '';
$output .= '<div id="children_pager">';
$output .= '<span id="prev_child">'; //display the previous child link
if ($prev_key) $output .= '<a href="/'.drupal_get_path_alias('node/'.$prev_key).'" title="Previous child">Previous child</a>';
$output .= '</span>';
$output .= '<span id="back_to_parent"><a href="/'.drupal_get_path_alias('node/'.$node->parent).'" title="Back to parent">Back to parent</a></span>'; //display the back to parent link
$output .= '<span id="next_child">'; //display the next child link
if ($next_key) $output .= '<a href="/'.drupal_get_path_alias('node/'.$next_key).'" title="Next child">Next child</a>';
$output .= '</span>';
$output .= '</div>';
print $output;
?>
</div><!-- /content-bottom -->
#2
Blocks are not node aware, but you can simply declare
$node = menu_get_object();to get the current node object, and this would work great.Unfortunately I switched away from NH - it was imposing a huge overhead for not much gain, but I should give it another try on the dev site with this :)