Skip to content

Instantly share code, notes, and snippets.

@dospuntocero
Created August 22, 2020 16:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dospuntocero/1a2ac394fbf49e20b69559878d26e4fb to your computer and use it in GitHub Desktop.
Save dospuntocero/1a2ac394fbf49e20b69559878d26e4fb to your computer and use it in GitHub Desktop.
next prev buttons for posts or pages in wordpress
<?php
//next prev buttons
$pagelist = get_posts('sort_order=asc');//use get_pages for pages
$pages = array();
foreach ($pagelist as $page) {
$pages[] += $page->ID;
}
$current = array_search(get_the_ID(), $pages);
$prevID = $pages[$current-1];
$nextID = $pages[$current+1];
?>
<a href="<?php echo get_permalink($prevID);?>">Previous</a>
<a href="<?php echo get_permalink($nextID);?>">Next</a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment