Reputation: 325
I have a website with my photos, divided to categories.
In my site, each photo is a post and they are displayed when a viewer enters a specific category.
I have next and previous buttons to move between posts, and I want to disable the "next" button when a viewer is in the last post.
What I need is to find a way to detect whether the current post is the last post in the category.
link to my website
Script for next and previous buttons:
<a href="<?php echo get_permalink(get_adjacent_post(true, '', false)); ?>"><div class="next"><p>NEXT</p></div></a>
<a href="<?php echo get_permalink(get_adjacent_post(true, '', true)); ?>"><div class="prev"><p>PREV</p></div></a>
Upvotes: 0
Views: 616
Reputation: 325
The correct conditioning is:
$nextpost = get_adjacent_post(true, '', false); if ($nextpost == "") { ?><a href="<?php echo get_permalink($nextpost); ?>"><div class="prev"><p>PREV</p></div></a><?php }
This solution was only possible thanks to the very elegnt direction suggested by the user "bsoist" which replied to this question.
Upvotes: 0
Reputation: 785
get_adjacent_post will return an empty string if no post exists.
Check to see if there is a post with something like this
$nextpost = get_adjacent_post(true, '', true);
if ($nextpost != "") {
?><a href="<?php echo get_permalink($nextpost); ?>"><div class="prev"><p>PREV</p></div></a><?php
}
Upvotes: 1