Last active
October 1, 2017 14:37
-
-
Save weartstudio/a6901ca2de48480a08505ede63641628 to your computer and use it in GitHub Desktop.
WordPress: Display different styled featured posts without WP_Query.
This file contains hidden or 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 | |
$fpi = 0; | |
global $post; | |
$featured_posts = get_posts( array( | |
'tag' => 'tag_as_you_want', //tag that you want to select the posts | |
'numberposts' => 5, //how many posts | |
) ); | |
if($featured_posts) { foreach ( $featured_posts as $post ) : setup_postdata( $post ); ?> | |
<!-- looping content --> | |
<?php if ($fpi == 0) : ?> | |
<!-- first post in featured posts --> | |
<article class="featured-big"> | |
<h2><?php the_title(); ?></h2> | |
</article> | |
<!-- first post in featured posts --> | |
<?php else: ?> | |
<!-- rest of the post --> | |
<article class="featured-small"> | |
<h3><?php the_title(); ?></h3> | |
</article> | |
<!-- rest of the post --> | |
<?php endif; $fpi++; ?> | |
<!-- looping content --> | |
<?php endforeach; } wp_reset_postdata(); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment