Created
August 22, 2020 16:19
-
-
Save dospuntocero/1a2ac394fbf49e20b69559878d26e4fb to your computer and use it in GitHub Desktop.
next prev buttons for posts or pages in wordpress
This file contains hidden or 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
<?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