开发者

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

开发者 https://www.devze.com 2023-01-11 03:39 出处:网络
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, h

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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消