How to display the latest blog post on a WordPress page

There are a lot of ways to display the latest blog post. They’re all complicated and ugly. I made a very simple WordPress plugin to handle this. It has no settings or options.

All you do is stick [get_latest_post] where you want the post to go.

You get markup like this, which you can style as you please:

<div class='latest-post'>
<p class='title'><a href='http://www.mysite.ca/blog/post'>Look ma, no hands!</a></p>
<p class='excerpt'>Today I rode a bicycle &hellip; <a href="http://www.mysite.ca/blog/post">Continue reading <span class="meta-nav">&rarr;</span></a></p>
</div>

Grab the plugin from GitHub or the WordPress plugin directory.

50 Responses to How to display the latest blog post on a WordPress page

  1. michael says:

    Hi there,

    first of all i must say great plug in I was looking for something like this and came across a lot of code to do this and frankly i was not looking for such complicated way to do this

    I have 1 more question and that is the following.

    Is it possible to call the read more link to the script right under the “excerpt” so not only the title is linked but my reader can also klik the read more link under need it?

    My best regards

    mike

  2. paul says:

    I’m sorry, but I don’t understand your question. The “read more” is a link.

  3. michael says:

    what i mean is this, i have now the title of the latest blog and some intro text of it, the title is a link trout the post
    What i would love to see is that under need the into text of the latest blog there is also the read more button
    So you wil get this

    My title of the the blog

    Some intro text of the blog that i have write

    read more

  4. paul says:

    Under the text of the post, there is a “continue reading” link. If you’re not seeing that, your post is too short (and is already displayed in its entirety).

  5. Meg says:

    I’m wondering if there is a way to use this plugin to display the last two posts.

  6. paul says:

    Try changing query_posts('showposts=1'); to query_posts('showposts=2');.

  7. Thomas says:

    Hi!
    Thanks for a nice plugin! Straightforward and easy to use – I like.

    Is there a way tom make the plugin show latest post in a special category?

  8. Thomas says:

    Hohooo!!!

    I made my first change in a wordpressplugin!! Hope you dont mind…

    I changed the code to this:

    105,
    'showposts' => 1
    );

    query_posts($args);
    while (have_posts()){
    the_post();
    $content .= "<a href='" . get_permalink() . "' rel="nofollow">" . get_the_title() . "</a>\n" .
    "" . get_the_excerpt() . "";
    }
    wp_reset_query();

    return "\n$content\n";
    }

    add_shortcode('get_latest_post', 'get_latest_post_html');
    ?>


    What do you think, will it work without problems?
    I cross my fingers :-)

    Regards
    Thomas

  9. Lerato says:

    I know my ins & out with joomla but not wordpress (silly ha!) Thanks for a Super-plugin. One must be really d*** not to figure this one out. Great work. Thumbs up!!!

  10. James Isles says:

    Nice plugin but is it possible to select which category of posts it shows or hide a category you do not wish to show?

    The reason for this is that I am using a slider in which uses posts to show the images and your plugin is alos showing these posts which I do not want to appear.

  11. D Ram says:

    Hi!
    Thanks for a nice plugin! Straightforward and easy to use – I like

  12. James E says:

    This plugin is just what I was looking for, except for one thing…

    In my current usage it is inserting a bunch of white space above the post excerpts. Check out an image here. Granted, my HTML coding skills are straight out of 1996, so that might be part of the problem…

    [get_latest_post]


  13. Martin says:

    Great plug in, thanks – all the other solutions for this seemed waaaay to complicated. Just one thing, can you style the post heading separately from the rest of the excerpt? I have only been able to do both or neither.

    Thanks

  14. paul says:

    Martin: Sure — just use class selectors:

    div.latest-post p.title { … }

    I should really change that to be be a h3, which makes more sense semantically.

  15. paul says:

    James Isles: modify the query_posts('showposts=1'); call to select the categories you want. If you want to make that change more generally applicable, you could pass an argument to the plugin, i.e. [get_latest_post category=foo]. See get_latest_tweets for an example of how to parse arguments.

  16. paul says:

    James E: would need to see your actual site to debug the white space problem.

  17. Jake says:

    I’m trying to display the two latest posts (I got that far) side by side. For example the first post on the left hand column and the second post on the right hand column. Is this possible with your plugin?

  18. paul says:

    You could do that with CSS

    div.latest-post { float: left; }
    [get_latest_post]
    <div style="clear: both;"></div>

  19. Karin says:

    Thanks for this plugin, it’s exactly what I was looking for!

    Question: Is there a way to add the post’s thumbnail?

    Also, tThe ‘read more’ function does not work on my site, any suggestions?

    Thanks!

  20. paul says:

    Karin:
    1. I imagine you could write PHP code to check for a thumbnail’s existence and insert it beside the_excerpt().
    2. What does “does not work” mean? What HTML does it generate? Is that link 404? Or is nothing generated?

  21. Karin says:

    1. Won’t be able to do this since I am not versed enough in writing code.
    2. It generates […] without a link. The headline links to the post however.

  22. Pradeep Singh says:

    How can I reduce excerpt limit in my latest post. Is there any way ?

  23. Pradeep Singh says:

    Hello Paul

    Thanks for the plugin.

    Paul I want to reduce the excerpt text into the latest post. can you please tell how to achieve this?

    Regards

  24. paul says:

    Pradeep: I don’t understand what you mean by “reduce the excerpt text into the latest post.”

  25. Kari says:

    Paul, thanks for the great plug-in! Exactly what I was looking for!

    Noticed that when I used it, it created tags in the other two columns on the front page, yet I don’t see those tags anywhere in the HTML, and they weren’t there when I had other content in column 1. Any idea what could be causing that?

    See http://chapmanjewelers.com.

    Thanks!

  26. paul says:

    Are you talking about the [raw]? Perhaps you disabled the raw html plugin by accident.

  27. Kari says:

    Yes, the [raw] tags. Is the raw html plugin part of your plug in, or would that be on the theme itself? I don’t know where to look to fix it.

  28. paul says:

    No — raw html is a totally separate plugin. Look on the plugins page!

  29. chris says:

    is there a way to use like to call directly in a page template. As in, im using a static front page with a specific template. can I use this plugin tag in that php?

  30. paul says:

    You can call this inside a template with do_shortcode().

  31. Mike says:

    Any way to display only one post? Also is this able to show video from my post?

  32. paul says:

    It only displays one post. It won’t show video because the_excerpt() only shows text content. You’d have to edit that part of the plugin yourself.

  33. Bryce Wilson says:

    This is EXACTLY what I am looking for, after many hours of trying to his with the code to no avail.

    A couple of questions:

    I too am not getting the Read More even though the post text is much longer. Instead I too get the […] text.

    –Ability to make the linked headline a larger font…

    –Ability to pull the thumbnail over…

    The last too have already been mentioned above, but I wanted to throw my “wishes” in the pot.

    Thanks again for a GREAT plug in!!!

    Bryce

  34. paul says:

    1. You can already style the headline as you please.
    2. The read more vs … comes from WordPress’ get_the_excerpt() call. I don’t render any of that.
    3. Thumbnail could be doable. I’ve never used them.

  35. Mattias says:

    Hi, this plugin is awsome, i have a question thoug. Im building a website using templates and i cant seem to figure out how to put your code into my html code.
    Im after a three column design in my content as shown below, but i cant add [get_latest_post] in my news area. Any thoughts or am i just doing something wrong?
    Any help would be super =D
    Thanks

    Text

    “Here i want” [get_latest_post]

    Text

  36. Robin says:

    Hi, first of all, great plugin, exactly what I was looking for! One question, though:

    I’d like to use this together with the “Boxer”-WP-Plugin (http://wordpress.org/extend/plugins/boxer/). If I put the shortcode onto a page, it works just fine, but it will not display inside of a box. The shortcode just appears there. Any ideas on how to fix that?

    Thanks and keep up the work!
    Robin

  37. James E. says:

    I’ve tried to tinker with this plugin to get it to display only one category. So far my feble attempts have not worked. Is it possible to limit to a single category?

  38. James E. says:

    Ignore my previous comment! I finally figured it out.

  39. Daniel Salan says:

    Hey! Nice little plugin! I have managed to style it and all. BUT, it generates the post WITHOUT links, that are in the original post, for example an email adress… i do not know why it does that.. :(

    Keep up the great work. Thanks!

    Kind regards

    Daniel

  40. That’s because it calls WordPress’ the_excerpt(), which generate text-only excerpts.

  41. Daniel Salan says:

    Hey Paul

    Hmmm is it possible to get links in there?

    Cheers

    Daniel

  42. You’d have to use a different part of the WordPress API. Read the_excerpt()’s documentation for more info.

  43. Daniel Salan says:

    Yes probably – ok many thanks!

    Kind regards

    Daniel

  44. Daniel Salan says:

    Fixed! :) Just replaced the get_the_excerpt() with get_the_content()

    voila!

    Thanks again

  45. Tomas says:

    Is it possible to limit the text displayed to 120 characters?

    Cheers

    Tomas

  46. Tomas says:

    Hi again

    Is just found an answer to my own question.

    here is the code – if anyone might be interested:

    function custom_excerpt_length( $length ) {
    return 20;
    }
    add_filter( ‘excerpt_length’, ‘custom_excerpt_length’, 999 );

    Cheers

    Tomas

  47. Jager says:

    Hi,

    Great plugin!

    I would like to display only about 30 words, and tried the code Tomas provided, but it did not work. I also would like it to show only post from category number 4, and tried to put: [get_latest_post category=4] but it doesn´t work. Would be really grateful for answer asap!

  48. Adrian says:

    Is there a way of using the shortcode [get_latest_post] to work in a widget? I tried to put it into the html text widget but it does not seem to work

    Cheers

    AD

  49. Amanda says:

    Hi Paul,

    The plugin works fine with text only excerpts – but how do I get a thumbnail or larger image to display?

  50. You’d have to modify it to use something other than the_excerpt().

Leave a Reply

Your email address will not be published. Required fields are marked *