Last active
December 11, 2015 22:58
-
-
Save krzysu/4672792 to your computer and use it in GitHub Desktop.
Wordpress: display last N posts on static page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$args = array( 'numberposts' => 2, 'post_status'=>"publish",'post_type'=>"post",'orderby'=>"post_date"); | |
$recentposts = get_posts( $args ); | |
if( empty( $recentposts )): | |
?> | |
<div class="three-from-four" id="latest-posts-box"> | |
<?php | |
global $post; | |
foreach($recentposts as $index => $post): | |
setup_postdata( $post ); | |
?> | |
<article class="one-from-two element <?= ($index % 2 == 1) ? 'last' : '' ?>"> | |
<h2> | |
<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"> | |
<?php the_title(); ?> | |
</a> | |
</h2> | |
<div class="element-body"> | |
<?php the_excerpt(); ?> | |
</div> | |
</article> | |
<?php | |
endforeach; | |
wp_reset_postdata(); | |
?> | |
</div> | |
<?php endif; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment