Skip to content

Instantly share code, notes, and snippets.

@yagamicoder
Last active September 23, 2016 02:51
Show Gist options
  • Save yagamicoder/49a87085e99aab14337edc81d9c3240a to your computer and use it in GitHub Desktop.
Save yagamicoder/49a87085e99aab14337edc81d9c3240a to your computer and use it in GitHub Desktop.
Display most recent posts
<?php
//Pass in recent post settings into $args array
$args = array('numberposts' => 5, 'order' => 'DESC', 'orderby' => 'post_date');
//Grab latest 5 posts
$postslist = get_posts($args);
//Loop through all posts and output the title, date, link to post and excerpt
foreach ($postslist as $post) : setup_postdata($post);
?>
<div class="latest-post">
<a class="latest-title" href="<?php the_permalink(); ?>"title="<?php the_title(); ?>" >
<?php the_title(); ?>
</a>
<span><?php echo the_date("l | F j, Y"); ?></span>
<p><?php echo get_the_excerpt(); ?></p>
<a class="read-more-btn" href="<?php the_permalink(); ?>">Read More...</a>
</div>
<?php endforeach; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment