Created
September 23, 2013 20:21
-
-
Save mwender/6676322 to your computer and use it in GitHub Desktop.
Retrieves next/prev links for WordPress pages or 'heirarchical' post_types.
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
global $post; | |
$pageID = $post->ID; | |
$args = array( | |
'parent' => 0, | |
'sort_order' => 'ASC', | |
'sort_column' => 'menu_order', | |
); | |
$pagelist = get_pages( $args ); | |
$pages = array(); | |
$x = 0; | |
foreach( $pagelist as $page ){ | |
$pages[$x] = $page; | |
if( $page->ID == $pageID ) | |
$current = $x; | |
$x++; | |
} | |
$prevID = $pages[$current - 1]->ID; | |
$nextID = $pages[$current + 1]->ID; | |
echo '<div class="navigation">'; | |
if( !empty( $prevID ) ) | |
echo '<a href="' . get_permalink( $prevID ) . '" class="btn">Previous: ' . get_the_title( $prevID ) . '</a>'; | |
if( !empty( $nextID ) ) | |
echo '<a href="' . get_permalink( $nextID ) . '" class="btn">Next: ' . get_the_title( $nextID ) . '</a>'; | |
echo '</div>'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment