# Jump to first post if .Next is nil

**URL:** <https://discourse.gohugo.io/t/jump-to-first-post-if-next-is-nil/27750>\
**Category:** support\
**Created:** [August 22, 2020, 12:35pm UTC](https://discourse.gohugo.io/t/jump-to-first-post-if-next-is-nil/27750 "2020-08-22T12:35:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![linuscodes](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/linuscodes/32/12205_2.png) [@linuscodes](https://discourse.gohugo.io/u/linuscodes)\
**Post date:** [August 22, 2020, 12:35pm UTC](https://discourse.gohugo.io/t/jump-to-first-post-if-next-is-nil/27750/1 "2020-08-22T12:35:51Z")

</div>

Hey there!

So my problem is that I try to loop though a list of posts and just use the `.Next` variable for navigation. And since `.Next` returns `nil` when there is no next post, I am searching for a way to jump back to the first post.

```auto
{{ if .NextInSection }}
   <a href="{{ .NextInSection.Permalink }}" class="wrapper">
      <span>
         <b>Next</b> Project
      </span>
      <h2>
         {{ .NextInSection.Title }}
      </h2>
   </a>
{{ end }}

```

This is what I have so far and I am really grateful for some help, thanks!

---

<div class="post-metadata">

**Author:** ![pointyfar](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/pointyfar/32/5797_2.png) [@pointyfar](https://discourse.gohugo.io/u/pointyfar)\
**Post date:** [August 22, 2020, 1:20pm UTC](https://discourse.gohugo.io/t/jump-to-first-post-if-next-is-nil/27750/2 "2020-08-22T13:20:41Z")

</div>

To clarify, you want to jump to the first page in the current section?

Untested, but you could do something like:

```auto
{{ if .NextInSection }}
    ...
{{ else }}

    {{ range last 1 .CurrentSection.Pages }}
        {{ .Permalink }}
    {{ end }}

{{ end }}

```

---

<div class="post-metadata">

**Author:** ![linuscodes](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/linuscodes/32/12205_2.png) [@linuscodes](https://discourse.gohugo.io/u/linuscodes)\
**Post date:** [August 22, 2020, 1:27pm UTC](https://discourse.gohugo.io/t/jump-to-first-post-if-next-is-nil/27750/3 "2020-08-22T13:27:06Z")

</div>

Yeah, exactly!

And it works perfectly, thanks a lot! Appreciate your time :3

Have a greate day!

---

<div class="post-metadata">

**Author:** ![system](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/system/32/1_2.png) [@system](https://discourse.gohugo.io/u/system)\
**Post date:** [August 24, 2020, 4:07pm UTC](https://discourse.gohugo.io/t/jump-to-first-post-if-next-is-nil/27750/5 "2020-08-24T16:07:28Z")

</div>

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.
