Last active
December 8, 2015 07:17
-
-
Save Aziz-Rahman/670ddcd79f09ea369b14 to your computer and use it in GitHub Desktop.
Get first and second post
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 | |
if (have_posts()) : | |
$counter = 1; | |
while (have_posts()) : | |
the_post(); | |
if( $counter == 1 ) { ?> | |
/*here the code to show this first post different*/ | |
<?php } elseif( $counter == 2 ) { ?> | |
/*here the code to show this second post different*/ | |
<?php } else { ?> | |
/*here the code to show all other posts*/ | |
<?php } | |
$counter++; | |
endwhile; | |
endif; | |
?> |
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 | |
global $wp_query; | |
$current_post = 2; | |
// The loop | |
if ( have_posts() ) { | |
while ( have_posts() ) { | |
the_post(); | |
if ( $wp_query->current_post == 0 ) : // get first post | |
// do something | |
else : | |
//do something | |
endif; | |
} | |
} else { | |
//do something | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment