Next/Previous Links in Codex sample code displays an error
-
Page: http://codex.wordpress.org/Next_and_Previous_Links
Code:
<?php $pagelist = get_pages('sort_column=menu_order&sort_order=asc'); $pages = array(); foreach ($pagelist as $page) { $pages[] += $page->ID; } $current = array_search(get_the_ID(), $pages); $prevID = $pages[$current-1]; $nextID = $pages[$current+1]; ?> <div class="navigation"> <?php if (!empty($prevID)) { ?> <div class="alignleft"> <a>" title="<?php echo get_the_title($prevID); ?>">Previous</a> </div> <?php } if (!empty($nextID)) { ?> <div class="alignright"> <a>" title="<?php echo get_the_title($nextID); ?>">Next</a> </div> <?php } ?> </div><!-- .navigation -->The error I see is when i am on either first or last posts of my custom post type. There is no previous post on the first post and then there is no next post on the last post.
“Notice: Undefined offset: -1 in…on line 47”.
Questions:
1. How i get the notice to stop appearing?
2. is there a way to make my first post have the last post as its previous link?
3. is there a way to make my last post have the first post as its next link?#2 and #3 combined would create an infinite loop for my posts. So that once they hit the end they can start back at the beginning.
The topic ‘Next/Previous Links in Codex sample code displays an error’ is closed to new replies.