When writing a blog, often you may want to make the latest post stand out from the post list. This is easy to achieve with Ghost CMS, by simply editing your theme with a few lines of code. This post will show you how to do exactly that.

We're going to assume that you want to show your latest post on your blog homepage, so you are going to edit the index.php file of your Ghost theme. To get the latest post, we need to use the get Ghost helper with some attributes:


{{#get "posts" limit="1"}}
{{/get}}

As you can see, we have used the limit attribute of the get helper, that limits the post fetching to only the latest post. Now, to show the post details, we can use the foreach loop to iterate through the posts (in this case, only one):


{{#get "posts" limit="1"}}
  {{#foreach posts}}
    <div class="latest-post">
      <h3><a href="{{url}}">{{title}}</a></h3>
      <p>{{excerpt}}</p>
    </div>
  {{/foreach}}
{{/get}}

This is good enough to show the basic post details from the latest post, however we should always check if the post we are displaying exists. So, we are going to add a simple check before the foreach loop:


{{#get "posts" limit="1"}}
  {{#if posts}}
    {{#foreach posts}}
      <div class="latest-post">
        <h3><a href="{{url}}">{{title}}</a></h3>
        <p>{{excerpt}}</p>
      </div>
    {{/foreach}}
  {{/if}}
{{/get}}

To recap - this code fetches the latest post, checks if it exists and displays its details. There's plenty more we could add here, like showing the authors, date, reading time but we will cover that another time. You can check out how displaying the latest post looks like in action in the Memo theme demo.