Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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