I'm using an answered posted here:
Prev/Next child navigation for current page? by user phife-dawz
The issue: I'm trying to run that inside a function by calling it inside a page template
if( is_page( array( '5145', '7', '8', '25' ) ) ) {
getPrevNext();
}
The function is placed inside the code snippet plugin and looks like this:
function getPrevNext() {
$pagelist = get_pages( "child_of=" . $post->post_parent . "&parent=" . $post->post_parent . "&sort_column=menu_order&sort_order=asc" );
$pages = array();
$pages = array();
foreach( $pagelist as $page ) {
$pages[] += $page->ID;
}
$current = array_search( $post->ID, $pages );
$prevID = $pages[ $current-1 ];
$nextID = $pages[ $current+1 ];
echo '<div class="navigation">';
if( ! empty( $prevID ) ) {
echo '<div class="alignleft">';
echo '<a href="';
echo get_permalink( $prevID );
echo '"';
echo 'title="';
echo get_the_title( $prevID );
echo'">Previous</a>';
echo "</div>";
}
if( ! empty( $nextID ) ) {
echo '<div class="alignright">';
echo '<a href="';
echo get_permalink( $nextID );
echo '"';
echo 'title="';
echo get_the_title( $nextID );
echo'">Next</a>';
echo "</div>";
}
}
The output I get is only showed with Next link but that also shows only a specific next page regarding the page we are viewing.