custom page/post navigation
-
Here is the piece of code that I currently have within my loop, that works well for navigating forward and backward between posts within a page…
if ( ! is_search()){ // if returning search results do not show any navigation if ( ! is_single()){ $wp_query->is_single = true; $next_post = get_adjacent_post(false,'',false) ; $prev_post = get_adjacent_post(false,'',true) ; if(!get_adjacent_post(false, '', false)) {echo '<div class="post-older post-older-top"><p><a href="#post-'; echo $prev_post->ID; echo '">Older Post ></a></p></div>'; } // if there are no newer articles elseif(!get_adjacent_post(false, '', true)) {echo '<div class="post-newer post-newer-top"><p><a href="#post-'; echo $next_post->ID; echo '">< Newer Post</a></p></div>'; } // if there are no older articles else {echo '<div class="post-newer post-newer-top"><p><a href="#post-'; echo $next_post->ID; echo '">< Newer Post</a></p></div>'; echo '<div class="post-older post-older-top"><p><a href="#post-'; echo $prev_post->ID; echo '">Older Post ></a></p></div>'; } $wp_query->is_single = false; }else {echo '<div class="post-newer post-newer-top"><p>'; next_post_link('%link','< Newer Post',false); echo '</p></div>'; echo '<div class="post-older post-older-top"><p>'; previous_post_link('%link','Older Post >',false); echo '</p></div>'; } }
However, when you come to the last post on the page, the link does nothing because the next post doesn’t exist on that page it’s on the next page…
So what I’m looking for is some sort of code that considers if the post is the last post of the page then make the link go to the next page of the blog.
Any ideas or help with this is greatly appreciated
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘custom page/post navigation’ is closed to new replies.