Get Latest Post?

Ask about a PHP problem here.
Post Reply
User avatar
FrederickGeek8
Posts: 148
Joined: Wed Nov 30, 2011 10:31 pm

Get Latest Post?

Post by FrederickGeek8 »

What is a good way, from your Blogging tutorial, to get the latest post and output it on a page (a preview of course)
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Get Latest Post?

Post by jacek »

Didn't I make a function to get the latest X posts ? Or the posts on a certain page, I think it was somethign like
function get_posts($page, $per_page);
if so they you can use this,
$latest = current(get_posts(1, 1));
to get the latest post. It's a slight misuse of the function, but probably what I would do :)
Image
User avatar
FrederickGeek8
Posts: 148
Joined: Wed Nov 30, 2011 10:31 pm

Re: Get Latest Post?

Post by FrederickGeek8 »

I finally got around to this and, no. You did not make that function that way. You did make a get_posts function but that just got all the blog posts and summaries
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Get Latest Post?

Post by jacek »

Maybe it was in the Pagination video then ? ;) Either way you could create a new function
function get_latest_post(){
    $sql = "SELECT `things` FROM `table` ORDER BY `post_id` DESC LIMIT 0, 1";
    
    /* More things go here.  */
}
Image
Post Reply