Skip to content

Instantly share code, notes, and snippets.

@jaredkc
Last active December 9, 2015 21:38
Show Gist options
  • Save jaredkc/4331714 to your computer and use it in GitHub Desktop.
Save jaredkc/4331714 to your computer and use it in GitHub Desktop.
WordPress Recent Posts
/**
* Outputs recent posts with the desired markup and data.
* Used in place of a widget to meet design requirements.
*
* Load in your theme template files with this <?php _my_recent_posts(); ?>
*/
function _my_recent_posts($recent_number = '8') {
$args = array( 'numberposts' => $recent_number );
$recent_posts = wp_get_recent_posts( $args );
echo '<ul class="recent-entries">';
foreach( $recent_posts as $recent ){
echo '<li>
<a href="' . get_permalink($recent['ID']) . '" title="Look ' . esc_attr($recent['post_title']) . '" >
<time class="entry-date" datetime="' . get_the_date( 'c' ) . '" pubdate>' . get_the_time( 'M d', $recent['ID'] ) . '</time>
<h1>' . $recent['post_title'] . '</h1>
</a>
</li> ';
}
echo '</ul>';
}
endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment