This is an old version of this answer!
Return to the current answerThis was posted by Darrin a few days back to a similar problem.
Put this in your functions.php.
Then use this at the bottom of your page.php, or which ever template file you're using.
Put this in your functions.php.
<?php
// function to find location within array
function relative_value_array($array, $current_val = '', $offset = 1) {
$values = array_values($array);
$current_val_index = array_search($current_val, $values);
if( isset($values[$current_val_index + $offset]) ) {
return $values[$current_val_index + $offset];
}
return false;
};
// previous page link function
function dbdb_prev_page_link() {
global $post;
if ( isset($post->post_parent) && $post->post_parent > 0 ) {
$children = get_pages('&sort_column=post_date&sort_order=asc&child_of='.$post->post_parent.'&parent='.$post->post_parent);
};
// throw the children ids into an array
foreach( $children as $child ) { $child_id_array[] = $child->ID; }
$prev_page_id = relative_value_array($child_id_array, $post->ID, -1);
$output = '';
if( '' != $prev_page_id ) {
$output .= '<a href="' . get_page_link($prev_page_id) . '"> « '. get_the_title($prev_page_id) . '</a>';
}
return $output;
};
//next page link function
function dbdb_next_page_link() {
global $post;
if ( isset($post->post_parent) && $post->post_parent > 0 ) {
$children = get_pages('&sort_column=post_date&sort_order=asc&child_of='.$post->post_parent.'&parent='.$post->post_parent);
};
// throw the children ids into an array
foreach( $children as $child ) { $child_id_array[] = $child->ID; }
$next_page_id = relative_value_array($child_id_array, $post->ID, 1);
$output = '';
if( '' != $next_page_id ) {
$output .= '<a href="' . get_page_link($next_page_id) . '">'. get_the_title($next_page_id) . ' »</a>';
}
return $output;
};
?>
Then use this at the bottom of your page.php, or which ever template file you're using.
<div class="navigation">
<div class="alignleft"><?php previous_post_link('« %link') ?></div>
<div class="alignright"><?php next_post_link('%link »') ?></div>
</div>
Pippin Williamson | 07/14/10 at 9:31pm





