Call second/ third most recent post/article

Hey all!

Just started using Hugo and I love it, though I’m making a homepage that has a section which uses different parallax scrolling speeds on elements that hold the most recent posts. Because of this, each of the four elements needs different HTML, I know this isn’t ideal but is there a way to call the second, third, fourth… etc most recent post?

Right now I have it calling the 4 more recent posts but in order to create each element separately It appears I need to create 4 unique post calls. Though I can’t find anywhere how you could call just the 2nd most recent post, or third most recent post.

Hopefully this makes sense and can be done.

Here’s the snippet calling for the four most recent. Each of the posts need different data-rellax properties.

{{- range first 1 .Data.Pages }}
	<a href="">
	  <article style="background-image:url(images/recording.jpg)" class="darken rellax" data-rellax-speed="-1" data-rellax-percentage="2">
		<div class="content">
		  <h3>{{ .Title }}</h3>
		  <hr>
		  <p>{{ range .Params.categories }}{{ . }},&nbsp;{{ end }}</p>
		</div>
	</article>
  </a>
{{- end }}

@leecampbell Sorry but writing from my phone, so can’t test, but I believe you can accomplish what you’re looking for with first and after…

 {{ range first 1 (after 3 .Data.Pages) }}
    {{ .Render "title" }}
{{ end }}

I believe this will grab the fourth piece of content in the list.

1 Like

Wow can’t believe I missed that, much appreciated worked like a charm.

  • Lee
1 Like