Actually, there is an added complication with the above. For some reason, if there is no next or previous post, the get_adjacent_id_smart() method returns the current post! So to fix this, you need something like this: