Instantly share code, notes, and snippets.

Embed
What would you like to do?
Showing latest post on home page with Jekyll
---
layout: default
---
<div class="blog-index">
{% assign post = site.posts.first %}
{% assign content = post.content %}
{% include post_detail.html %}
</div>
<h1 class="entry-title">
{% if page.title %}
<a href="{{ root_url }}{{ page.url }}">{{ page.title }}</a>
{% endif %}
{% if post.title %}
<a href="{{ root_url }}{{ post.url }}">{{ post.title }}</a>
{% endif %}
</h1>
<div class="entry-content">{{ content }}</div>
@nimbupani

This comment has been minimized.

Show comment
Hide comment
@nimbupani

nimbupani Dec 2, 2011

This was the easiest hack I could get away with while sharing the included snippet with individual post page as well. I am sure this is quite the incorrect way to go about it.

Owner

nimbupani commented Dec 2, 2011

This was the easiest hack I could get away with while sharing the included snippet with individual post page as well. I am sure this is quite the incorrect way to go about it.

@xonecas

This comment has been minimized.

Show comment
Hide comment
@xonecas

xonecas Feb 28, 2013

It might be a hack, but now it's not only you using it. :-) Thank you

xonecas commented Feb 28, 2013

It might be a hack, but now it's not only you using it. :-) Thank you

@nathanlong

This comment has been minimized.

Show comment
Hide comment
@nathanlong

nathanlong commented Apr 4, 2013

👍

@girvo

This comment has been minimized.

Show comment
Hide comment
@girvo

girvo Apr 28, 2013

For some reason it doesn't work in displaying the title when the post is accessed directly on my setup :( I'll see if I can work out why

girvo commented Apr 28, 2013

For some reason it doesn't work in displaying the title when the post is accessed directly on my setup :( I'll see if I can work out why

@flxw

This comment has been minimized.

Show comment
Hide comment
@flxw

flxw Jul 19, 2013

Nice! Saved me some tryouts!

flxw commented Jul 19, 2013

Nice! Saved me some tryouts!

@mattr-

This comment has been minimized.

Show comment
Hide comment
@mattr-

mattr- Aug 29, 2013

Nice! Mind if I use this in a blog post series I intend to start on Jekyll tips and tricks? Credit will be given.

mattr- commented Aug 29, 2013

Nice! Mind if I use this in a blog post series I intend to start on Jekyll tips and tricks? Credit will be given.

@escotilha

This comment has been minimized.

Show comment
Hide comment
@escotilha

escotilha Aug 29, 2013

Thanks! Helped me a lot!

escotilha commented Aug 29, 2013

Thanks! Helped me a lot!

@zypeh

This comment has been minimized.

Show comment
Hide comment
@zypeh

zypeh Oct 10, 2013

Awesome! I am gonna use this in my site. Thanks :-)

zypeh commented Oct 10, 2013

Awesome! I am gonna use this in my site. Thanks :-)

@olegafx

This comment has been minimized.

Show comment
Hide comment
@olegafx

olegafx Feb 11, 2014

Awesome, thank you!

olegafx commented Feb 11, 2014

Awesome, thank you!

@MindGeek

This comment has been minimized.

Show comment
Hide comment
@MindGeek

MindGeek Apr 1, 2014

Awesome!

MindGeek commented Apr 1, 2014

Awesome!

@Tug

This comment has been minimized.

Show comment
Hide comment
@Tug

Tug Apr 21, 2014

Add {% assign page = post %} if the title does not show up.

Tug commented Apr 21, 2014

Add {% assign page = post %} if the title does not show up.

@chrisanthropic

This comment has been minimized.

Show comment
Hide comment
@chrisanthropic

chrisanthropic May 24, 2014

Anyone still using this know if it's possible to add pagination to it that points to prev post and not '/blog/page/2' ?

chrisanthropic commented May 24, 2014

Anyone still using this know if it's possible to add pagination to it that points to prev post and not '/blog/page/2' ?

@wilsonusman

This comment has been minimized.

Show comment
Hide comment
@wilsonusman

wilsonusman Sep 14, 2014

Do you know why am I showing more than the first post?

wilsonusman commented Sep 14, 2014

Do you know why am I showing more than the first post?

@coderdiaz

This comment has been minimized.

Show comment
Hide comment
@coderdiaz

coderdiaz Feb 1, 2015

Working good! 😄

coderdiaz commented Feb 1, 2015

Working good! 😄

@kencrocken

This comment has been minimized.

Show comment
Hide comment
@kencrocken

kencrocken commented Apr 9, 2015

🍻

@lacostenycoder

This comment has been minimized.

Show comment
Hide comment
@lacostenycoder

lacostenycoder Apr 22, 2015

🍻 what he said ^^

lacostenycoder commented Apr 22, 2015

🍻 what he said ^^

@eenblam

This comment has been minimized.

Show comment
Hide comment
@eenblam

eenblam Jun 20, 2015

Since this is still a topic of interest several years later, it's probably worth mentioning the Jekyll Bootstrap docs.

eenblam commented Jun 20, 2015

Since this is still a topic of interest several years later, it's probably worth mentioning the Jekyll Bootstrap docs.

@cherrot

This comment has been minimized.

Show comment
Hide comment
@cherrot

cherrot Jul 11, 2015

Awesome hack!

cherrot commented Jul 11, 2015

Awesome hack!

@onewithnow

This comment has been minimized.

Show comment
Hide comment
@onewithnow

onewithnow Aug 10, 2015

Works! Thank you so much.

onewithnow commented Aug 10, 2015

Works! Thank you so much.

@TangChr

This comment has been minimized.

Show comment
Hide comment
@TangChr

TangChr Oct 12, 2015

Works like a charm. Thanks!

TangChr commented Oct 12, 2015

Works like a charm. Thanks!

@mhlibchuk

This comment has been minimized.

Show comment
Hide comment
@mhlibchuk

mhlibchuk Nov 29, 2015

Hi there, I know I'm a bit late, but thanks! Just what I was looking for.

mhlibchuk commented Nov 29, 2015

Hi there, I know I'm a bit late, but thanks! Just what I was looking for.

@terrencebrown

This comment has been minimized.

Show comment
Hide comment
@terrencebrown

terrencebrown Jan 21, 2016

many thanks buddy!

terrencebrown commented Jan 21, 2016

many thanks buddy!

@pabloselin

This comment has been minimized.

Show comment
Hide comment
@pabloselin

pabloselin Apr 14, 2016

Thanks! this helped me understand Jekyll and get started with some templating...

pabloselin commented Apr 14, 2016

Thanks! this helped me understand Jekyll and get started with some templating...

@michelinux

This comment has been minimized.

Show comment
Hide comment
@michelinux

michelinux Sep 9, 2017

Thank you. Just what I was looking for. Even after so many years.

michelinux commented Sep 9, 2017

Thank you. Just what I was looking for. Even after so many years.

@BradCoffield

This comment has been minimized.

Show comment
Hide comment
@BradCoffield

BradCoffield Nov 15, 2017

Thanks a lot. I just needed a simple link to the latest post and reading your stuff helped me.

Just FYI for others: <a href="{{site.posts.first.url}}">{{site.posts.first.title}}</a>

BradCoffield commented Nov 15, 2017

Thanks a lot. I just needed a simple link to the latest post and reading your stuff helped me.

Just FYI for others: <a href="{{site.posts.first.url}}">{{site.posts.first.title}}</a>

@bildungsroman

This comment has been minimized.

Show comment
Hide comment
@bildungsroman

bildungsroman Jul 10, 2018

I know this is a bit late, but now how do you show the rest of your posts if you're using pagination? I know an easy way would be to do offset:1, but with pagination this offsets the first post on each page, which is not what I want. Is there a way to use assign, i.e. {% assign remainingposts = site.posts offset:1 %} or something like that?

bildungsroman commented Jul 10, 2018

I know this is a bit late, but now how do you show the rest of your posts if you're using pagination? I know an easy way would be to do offset:1, but with pagination this offsets the first post on each page, which is not what I want. Is there a way to use assign, i.e. {% assign remainingposts = site.posts offset:1 %} or something like that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment