jeffkee
jeffkee

Reputation: 5238

How to Check if Current Post is the First or Last Post in Wordpress

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.

Upvotes: 4

Views: 4623

Answers (1)

Jan Fabry
Jan Fabry

Reputation: 7351

If you just want to check for their existence and don't need the link, you should use get_previous_post and get_next_post. They don't apply unnecessary formatting that you would ignore if you just use it in an if test. You can still get a link from the post object it returns by passing it to get_permalink.

Upvotes: 4

Related Questions