Skip to content

Instantly share code, notes, and snippets.

@Aziz-Rahman
Last active December 8, 2015 07:17
Show Gist options
  • Save Aziz-Rahman/670ddcd79f09ea369b14 to your computer and use it in GitHub Desktop.
Save Aziz-Rahman/670ddcd79f09ea369b14 to your computer and use it in GitHub Desktop.
Get first and second post
<?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;
?>
<?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