Skip to content

Instantly share code, notes, and snippets.

@raewrites
Created January 16, 2015 06:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save raewrites/9752e257ce33d2f210ec to your computer and use it in GitHub Desktop.
Save raewrites/9752e257ce33d2f210ec to your computer and use it in GitHub Desktop.
List of Recent Posts
<?php
$args = array(
'posts_per_page' => '4',
'exclude' => array( $post->ID )
);
// get posts
$posts = get_posts( $args );
// check if any posts are returned
if ( $posts ) { ?>
<section class="recent-posts clear">
<?php foreach ($posts as $post ) { ?>
<?php setup_postdata( $post ); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class( 'left' ); ?>>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
<?php post_thumbnail( 'thumbnail' );?>
</a>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
<?php the_title(); ?>
</a>
</article>
<?php } ?>
</section>
<?php }
/* Restore original Post Data */
wp_reset_postdata();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment