On my website, greggant.com I have a small section of my homepage where it always displays the title of my most current blog post. Prior to using Jekyll back when my blog was hosted on Tumblr, I used the API to grab the latest post via a URL. On Jekyll, the solution is even easier: Create a dummy template that only includes the page title and use PHP to write the blog post title.

Step 1: Create a blank template in _layouts

I created a template I named blank.html, the entire contents are one line:

  {{ content }}   

Step 2: Create a url

Since the script I'll be using is all for public access, I kept it simple and decided to make a new page in the root of my blog. I named it currentpost.html.


  --- 
layout: blank
title: Inaudible Discussion
---
{% for post in site.posts limit:1 %}
{{post.title }}
{% endfor %}

It'd be possible to create a URL directly to the page, but for this solution, I opted in for absolutely the most minimum amount of work seeing I'd rather link from my portfolio to my blog's homepage instead of the the actual post..

Step 3: Creating the script in PHP

Lastly, comes the PHP, and it looks as such:

<a href="http://blog.greggant.com">
<?php $url = "http://blog.greggant.com/currentpost.html";
$str = file_get_contents($url); echo $str; ?>	</a>