Loop - how to get previous/next post for first/last post?
I have a simple loop for a JS slider, I want to display previous and next posts titles on my slide, but I can't get previous post title on the first slide (because apparently first post have no previous posts):
$prev_post = $loop-posts[$loop-current_post - 1]; // ALWAYS NULL FOR FIRST POST :(
$next_post = $loop-posts[$loop-current_post + 1]; // ALWAYS NULL FOR THE LAST POST
echo $next_post-post_title;
echo $next_post-post_title;
Is there any easy way to fix that?