How to check if current message is first or last in Wordpress

I checked Google and went through the Wordpress template tags, but I still can’t figure it out - in the single.php template file that is used to display a specific message, how can I check if this post is the latest or oldest post? Essentially, I need to know if this is the first or last message of all my posts.

+3
source share
1 answer

If you just want to verify their existence and don't need a link, you should use get_previous_postand get_next_post. They do not use unnecessary formatting, which you ignore if you just use it in a test if. You can still get the link from the post object that it returns by passing it get_permalink.

+2
source

Source: https://habr.com/ru/post/1759437/


All Articles