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.

Join the Conversation

50 Comments

  1. 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. 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

  3. 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).

  4. 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?

  5. 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

  6. 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!!!

  7. 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.

  8. 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]


  9. 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

  10. 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.

  11. 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.

  12. 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?

  13. 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!

  14. 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?

  15. 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.

  16. 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

  17. 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!

  18. 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.

  19. 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?

  20. 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.

  21. 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

  22. 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.

  23. 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

  24. 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

  25. 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?

  26. 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

  27. 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

  28. 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!

  29. 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

Leave a comment

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