Create a gist now

Instantly share code, notes, and snippets.

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
Owner

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
xonecas commented Feb 28, 2013

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

@nathanlong

👍

@girvo
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
flxw commented Jul 19, 2013

Nice! Saved me some tryouts!

@mattr-
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

Thanks! Helped me a lot!

@zypeh
zypeh commented Oct 10, 2013

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

@olegafx
olegafx commented Feb 11, 2014

Awesome, thank you!

@MindGeek
MindGeek commented Apr 1, 2014

Awesome!

@Tug
Tug commented Apr 21, 2014

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

@chrisanthropic

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

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

@coderdiaz

Working good! 😄

@kencrocken

🍻

@lacostenycoder

🍻 what he said ^^

@eenblam
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
cherrot commented Jul 11, 2015

Awesome hack!

@onewithnow

Works! Thank you so much.

@TangChr
TangChr commented Oct 12, 2015

Works like a charm. Thanks!

@mhlibchuk

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

@terrencebrown

many thanks buddy!

@pabloselin

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

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