Last active
December 15, 2015 14:39
-
-
Save schikulski/5275861 to your computer and use it in GitHub Desktop.
Wordpress: First as featured, then two column posts
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 | |
$do_not_duplicate=0; //initialize $do_not_duplicate | |
if(!is_paged()): //is_paged returns true if we are on page 2,3,... So if we're on page 1 do: | |
$my_query = new WP_Query('posts_per_page=1'); // Gets the first post | |
while ($my_query->have_posts()) : $my_query->the_post(); | |
$do_not_duplicate = $post->ID; | |
// Do stuff for the first article | |
endwhile; | |
endif; | |
// gets the rest of the posts | |
if (have_posts()) : | |
while (have_posts()) : the_post(); | |
if( $post->ID == $do_not_duplicate ) continue; // If is not the first post do: | |
if( $wp_query->current_post%2 == 0 ) echo "\n".'<div class="twocolumnpostswrap">'."\n"; // the two-column wrapper | |
// The other posts | |
if( $wp_query->current_post%2 == 1 || $wp_query->current_post == $wp_query->post_count-1 ) echo '</div> <!--/.twocolumnpostswrap-->'."\n"; | |
endwhile; | |
endif; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment