I checked Google and went through the WordPress template tags but I still can’t figure this out – in the single.php template file, which is the one used to display a specific post, how do I check whether this post is the most recent one OR the oldest post? Essentially I need to know whether this is first or last post out of all my posts.
Leave a Reply
You must be logged in to post a comment.
If you just want to check for their existence and don’t need the link, you should use
get_previous_post
andget_next_post
. They don’t apply unnecessary formatting that you would ignore if you just use it in anif
test. You can still get a link from the post object it returns by passing it toget_permalink
.