Display latest 5 posts on homepage
<p>I'm currently using a custom made Twentytwelve child theme and would like to display the last 5 posts on the homepage using a shortcode. I have tried using the code below (added to <code>functions.php</code>) but to no avail - when I add the shortcode to the homepage, it doesn't display anything although as far as I can see, it should and I have a test post live.</p>

<pre><code>function custom_prev_posts($limit = 5){
global $wpdb, $post;
$html = '';
$prev_posts = $wpdb-&gt;get_results( $wpdb-&gt;prepare( "SELECT * FROM $wpdb-&gt;posts WHERE $wpdb-&gt;posts.post_date &lt; '%s' AND $wpdb-&gt;posts.post_type = 'post' AND $wpdb-&gt;posts.post_status = 'publish' ORDER BY $wpdb-&gt;posts.post_date DESC LIMIT $limit", $post-&gt;post_date ) ); 

if($prev_posts){
$html .= '&lt;ul&gt;';
foreach ( $prev_posts as $prev_post  ) {
$html .= '&lt;li&gt;&lt;a href="' . get_permalink( $prev_post-&gt;ID ) . '"&gt;' .$prev_post-&gt;post_title . '&lt;/a&gt;&lt;/li&gt;';
}
$html .= '&lt;/ul&gt;';
}
return $html;
}

add_shortcode('last5', 'custom_prev_posts');
</code></pre>

<p>I'm thinking the issue may be related to the Twentytwelve theme. Any ideas what I'm doing wrong or does anyone know of a working way to display the latest 5 posts inside a page?</p>
