# Display only last post on index.html

**URL:** <https://zola.discourse.group/t/display-only-last-post-on-index-html/2342>\
**Category:** Support\
**Created:** [October 25, 2024, 2:18pm UTC](https://zola.discourse.group/t/display-only-last-post-on-index-html/2342 "2024-10-25T14:18:37Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![lapisdecor](https://yyz2.discourse-cdn.com/free1/user_avatar/zola.discourse.group/lapisdecor/32/1345_2.png) [@lapisdecor](https://zola.discourse.group/u/lapisdecor)\
**Post date:** [October 25, 2024, 2:18pm UTC](https://zola.discourse.group/t/display-only-last-post-on-index-html/2342/1 "2024-10-25T14:18:38Z")

</div>

Hi there I’m was doing a static site by hand and I thought I would try zola instead.  
The site is quite simple, it’s for displaying an image and have a button for previous and another for next. I wanted to display only the last post on the first page you see, so I edited index.html with

```auto
<div>
	{% set page = get_page(path="tiras/second.md") %}
	{{ page.content }}
</div>

```

but it’s showing the code instead of the page.

I also want to replace second.md by something that refers allways to the last post.  
thanks in advance.

---

<div class="post-metadata">

**Author:** ![lapisdecor](https://yyz2.discourse-cdn.com/free1/user_avatar/zola.discourse.group/lapisdecor/32/1345_2.png) [@lapisdecor](https://zola.discourse.group/u/lapisdecor)\
**Post date:** [October 25, 2024, 7:41pm UTC](https://zola.discourse.group/t/display-only-last-post-on-index-html/2342/2 "2024-10-25T19:41:23Z")

</div>

Oh I was not using “safe”… nevermind.

---

<div class="post-metadata">

**Author:** ![lapisdecor](https://yyz2.discourse-cdn.com/free1/user_avatar/zola.discourse.group/lapisdecor/32/1345_2.png) [@lapisdecor](https://zola.discourse.group/u/lapisdecor)\
**Post date:** [October 25, 2024, 8:12pm UTC](https://zola.discourse.group/t/display-only-last-post-on-index-html/2342/3 "2024-10-25T20:12:45Z")

</div>

I still don’t get how do I get the last post.  
Does zola has a section.pages.last ?

---

<div class="post-metadata">

**Author:** ![lapisdecor](https://yyz2.discourse-cdn.com/free1/user_avatar/zola.discourse.group/lapisdecor/32/1345_2.png) [@lapisdecor](https://zola.discourse.group/u/lapisdecor)\
**Post date:** [October 25, 2024, 8:52pm UTC](https://zola.discourse.group/t/display-only-last-post-on-index-html/2342/4 "2024-10-25T20:52:20Z")

</div>

I was trying to do it like this, but it doesn’t work

```auto
<div>
	{% set last_page = 0 %}
	{% for page in section.pages %}
	  {% set last_page = loop.index %}
	{% endfor %}
	{{last_page}}
	{% set page = get_page(path=f"tiras/tira{last_page}.md") %}
	{{ page.content | safe }}
</div>

```

---

<div class="post-metadata">

**Author:** ![lapisdecor](https://yyz2.discourse-cdn.com/free1/user_avatar/zola.discourse.group/lapisdecor/32/1345_2.png) [@lapisdecor](https://zola.discourse.group/u/lapisdecor)\
**Post date:** [October 27, 2024, 10:45am UTC](https://zola.discourse.group/t/display-only-last-post-on-index-html/2342/5 "2024-10-27T10:45:44Z")

</div>

We actually just need:

```auto
{% set section = get_section(path="tiras/_index.md") %}
		
	{% for page in section.pages %}
		{% if loop.first %}
			<h1>{{ page.title }}</h1>
			{{ page.content | safe }}

```

---

<div class="post-metadata">

**Author:** ![welpo](https://yyz2.discourse-cdn.com/free1/user_avatar/zola.discourse.group/welpo/32/1087_2.png) [@welpo](https://zola.discourse.group/u/welpo)\
**Post date:** [October 28, 2024, 9:58am UTC](https://zola.discourse.group/t/display-only-last-post-on-index-html/2342/6 "2024-10-28T09:58:40Z")

</div>

If you’re just trying to get the last element (and don’t care about the other items), this should work:

```tera
{% section.pages | last %}

```

From the [Tera docs](https://keats.github.io/tera/docs/).

---

<div class="post-metadata">

**Author:** ![lapisdecor](https://yyz2.discourse-cdn.com/free1/user_avatar/zola.discourse.group/lapisdecor/32/1345_2.png) [@lapisdecor](https://zola.discourse.group/u/lapisdecor)\
**Post date:** [October 30, 2024, 9:59pm UTC](https://zola.discourse.group/t/display-only-last-post-on-index-html/2342/7 "2024-10-30T21:59:31Z")

</div>

Thanks!
