Skip to content

Instantly share code, notes, and snippets.

@figureone
Created December 8, 2012 03:19
Show Gist options
  • Save figureone/4238427 to your computer and use it in GitHub Desktop.
Save figureone/4238427 to your computer and use it in GitHub Desktop.
WordPress: print link to next page
<?php
$allPages = get_pages(array(
'sort_column' => 'menu_order',
'sort_order' => 'asc',
));
for ($i=0; $i<count($allPages); $i++) // advance iterator to current page
if ($allPages[$i]->ID == $post->ID)
break;
$nextURI = $i<count($allPages)-1 ? get_permalink($allPages[$i+1]->ID) : "";
$nextTitle = strlen($nextURI)>0 ? $allPages[$i+1]->post_title : "";
?>
<a href="<?php print $nextURI; ?>"><?php print $nextTitle; ?></a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment