# Question about site.posts values

**URL:** <https://talk.jekyllrb.com/t/question-about-site-posts-values/1972>\
**Category:** Help\
**Created:** [July 16, 2018, 6:33pm UTC](https://talk.jekyllrb.com/t/question-about-site-posts-values/1972 "2018-07-16T18:33:38Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![raymondcamden](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/raymondcamden/32/547_2.png) [@raymondcamden](https://talk.jekyllrb.com/u/raymondcamden)\
**Post date:** [July 16, 2018, 6:33pm UTC](https://talk.jekyllrb.com/t/question-about-site-posts-values/1972/1 "2018-07-16T18:33:38Z")

</div>

Probably a dumb question - I’m trying to get the first and last post for my site. I’m using this to capture the posts:

```
{% capture lastPost %}{{ site.posts | first }}{% endcapture %}
{% capture firstPost %}{{ site.posts | last }}{% endcapture %}

```

But if I `{{lastPost.title}}` I get nothing. I then noticed that if I did `{{lastPost}}` I got the rendered output of the post itself. How would I get the post “object” instead?

---

<div class="post-metadata">

**Author:** ![raymondcamden](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/raymondcamden/32/547_2.png) [@raymondcamden](https://talk.jekyllrb.com/u/raymondcamden)\
**Post date:** [July 16, 2018, 6:43pm UTC](https://talk.jekyllrb.com/t/question-about-site-posts-values/1972/2 "2018-07-16T18:43:29Z")

</div>

And duh - now I see it. I’m rendering the page. Sigh. So let me say this - I was able to output the last page title and date like so:

```
{{ site.posts[0].title }} ({{ site.posts[0].date | date: "%Y-%m-%d" }})

```

But every attempt to get the last value of site.posts has failed for me. I tried site.posts[site.posts.size-1] but that returned nothing.

---

<div class="post-metadata">

**Author:** ![raymondcamden](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/raymondcamden/32/547_2.png) [@raymondcamden](https://talk.jekyllrb.com/u/raymondcamden)\
**Post date:** [July 16, 2018, 6:48pm UTC](https://talk.jekyllrb.com/t/question-about-site-posts-values/1972/3 "2018-07-16T18:48:07Z")

</div>

I’ve tried this to get the “last index”:

```
{% capture lastdx %}{{ site.posts.size | minus: 1 }}{% endcapture %}

```

if I output lastdx, I get 61. If I do:

```
{{ site.posts[lastdx].title }

```

I get nothing. If I change `lastdx` to a hard coded value of 61, it works.

---

<div class="post-metadata">

**Author:** ![mmistakes](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/mmistakes/32/2169_2.png) [@mmistakes](https://talk.jekyllrb.com/u/mmistakes)\
**Post date:** [July 16, 2018, 10:34pm UTC](https://talk.jekyllrb.com/t/question-about-site-posts-values/1972/4 "2018-07-16T22:34:04Z")

</div>

Not tested, but I think `capture` assigns the variable as a string, which could explain why it’s not working since it expects a number.

Maybe try [filtering](https://shopify.github.io/liquid/filters/abs/) `lastdx` with something like `{{ lastdx | abs }}` before you try to call it on `site.posts` to convert the string to a number.

---

<div class="post-metadata">

**Author:** ![mmistakes](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/mmistakes/32/2169_2.png) [@mmistakes](https://talk.jekyllrb.com/u/mmistakes)\
**Post date:** [July 16, 2018, 10:37pm UTC](https://talk.jekyllrb.com/t/question-about-site-posts-values/1972/5 "2018-07-16T22:37:23Z")

</div>

You could also use `assign` which might be cleaner.

`{% assign lastdx = site.posts.size | minus: 1 %}`

---

<div class="post-metadata">

**Author:** ![mmistakes](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/mmistakes/32/2169_2.png) [@mmistakes](https://talk.jekyllrb.com/u/mmistakes)\
**Post date:** [July 16, 2018, 10:45pm UTC](https://talk.jekyllrb.com/t/question-about-site-posts-values/1972/6 "2018-07-16T22:45:11Z")

</div>

Oh and even simpler are [`first`](https://shopify.github.io/liquid/filters/first/) and [`last`](https://shopify.github.io/liquid/filters/last/). Use dot notation and you can access the entire object.

In your case `{{ site.posts.first.title }}` and `{{ site.posts.last.title }}` will get the `title` of the first and last posts. You can replace `title` with any variable available in the post’s YAML Front Matter… `date`, `content`, `excerpt`, etc.

---

<div class="post-metadata">

**Author:** ![raymondcamden](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/raymondcamden/32/547_2.png) [@raymondcamden](https://talk.jekyllrb.com/u/raymondcamden)\
**Post date:** [July 17, 2018, 1:19am UTC](https://talk.jekyllrb.com/t/question-about-site-posts-values/1972/7 "2018-07-17T01:19:17Z")

</div>

Awesome - all of these answers helped me learn a bit. Thank you!
