# How can I check whether the post I am in is the first or the last?

**URL:** <https://forum.ghost.org/t/how-can-i-check-whether-the-post-i-am-in-is-the-first-or-the-last/43152>\
**Category:** Developer help\
**Created:** [December 4, 2023, 1:29pm UTC](https://forum.ghost.org/t/how-can-i-check-whether-the-post-i-am-in-is-the-first-or-the-last/43152 "2023-12-04T13:29:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![SF90](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/sf90/32/27460_2.png) [@SF90](https://forum.ghost.org/u/SF90)\
**Post date:** [December 4, 2023, 1:29pm UTC](https://forum.ghost.org/t/how-can-i-check-whether-the-post-i-am-in-is-the-first-or-the-last/43152/1 "2023-12-04T13:29:48Z")

</div>

Hi, I am I want to make the next news part, if the user is in the first post, it should show the next post, if the user is in the last post, it should show the next post. Otherwise it should always show the next post.

The code I found in the documentation did not fully meet my needs:

![image](https://us1.discourse-cdn.com/flex015/uploads/ghost2/original/3X/8/0/80e809f66139d697480d8d26adbdb772846c2dba.png)

And I tried something like this:

![image](https://us1.discourse-cdn.com/flex015/uploads/ghost2/original/3X/d/f/df9c5d7c1aaff60ecf9471a4df183b7b007d6e19.png)

How can I tell if the post is the first or the last?

---

<div class="post-metadata">

**Author:** ![Cathy\_Sarisky](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/cathy_sarisky/32/25750_2.png) [@Cathy\_Sarisky](https://forum.ghost.org/u/Cathy_Sarisky)\
**Post date:** [December 4, 2023, 1:52pm UTC](https://forum.ghost.org/t/how-can-i-check-whether-the-post-i-am-in-is-the-first-or-the-last/43152/2 "2023-12-04T13:52:05Z")

</div>

Not tested, but I’d try something like  
{{#next\_post}}  
{{#if url}}  
– do all the stuff you want to do if the post exists  
{{/if}}  
{{/next\_post}}

That way you get into the next post context if it exists, then check that the url exists in that context, because if it doesn’t, you don’t want to render that section anyway.

If that doesn’t meet your needs, please post more about what you’re trying to do?

---

<div class="post-metadata">

**Author:** ![SF90](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/sf90/32/27460_2.png) [@SF90](https://forum.ghost.org/u/SF90)\
**Post date:** [December 7, 2023, 8:55am UTC](https://forum.ghost.org/t/how-can-i-check-whether-the-post-i-am-in-is-the-first-or-the-last/43152/3 "2023-12-07T08:55:21Z")

</div>

Thank you for your response,

What I’m trying to do is, if the user is on the latest post, suggest the previous one; otherwise, suggest the next post.

---

<div class="post-metadata">

**Author:** ![RyanF](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/ryanf/32/17448_2.png) [@RyanF](https://forum.ghost.org/u/RyanF)\
**Post date:** [December 7, 2023, 8:51pm UTC](https://forum.ghost.org/t/how-can-i-check-whether-the-post-i-am-in-is-the-first-or-the-last/43152/4 "2023-12-07T20:51:55Z")

</div>

I think I’d use CSS to solve this problem. Show both the `next` and `prev` links, but hide the second when there’s two:

```html
<div class="next-and-previous-links">
{{#next_post}}
   <a href="{{url}}">next</a>
{{/next_post}}

{{#prev_post}}
   <a href="{{url}}">prev</a>
{{/prev_post}}
</div>

```

```css
.next-and-previous-links a + a {
   display: none;
}

```

---

<div class="post-metadata">

**Author:** ![SF90](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/sf90/32/27460_2.png) [@SF90](https://forum.ghost.org/u/SF90)\
**Post date:** [December 8, 2023, 8:10am UTC](https://forum.ghost.org/t/how-can-i-check-whether-the-post-i-am-in-is-the-first-or-the-last/43152/5 "2023-12-08T08:10:44Z")

</div>

Yes, this could work, thank you.
