Page 1 of 1

Get Latest Post?

Posted: Thu Jul 12, 2012 11:11 pm
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)

Re: Get Latest Post?

Posted: Fri Jul 13, 2012 2:14 pm
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 :)

Re: Get Latest Post?

Posted: Thu Jul 26, 2012 3:49 pm
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

Re: Get Latest Post?

Posted: Sun Jul 29, 2012 1:47 am
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.  */
}