Created
June 17, 2012 08:22
-
-
Save onishiweb/2943884 to your computer and use it in GitHub Desktop.
Select the first 2 posts on a blog and use a different template to display them
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 | |
// Get the WP global paged - this tells you what page number you're on | |
// (returns either 0 (I think) or page number) | |
global $paged; | |
// Check to see whether we've moved on to another page | |
if( $paged < 2): | |
// Set a counter | |
$count = 0; | |
endif; | |
?> | |
<?php if ( have_posts() ) : ?> | |
<?php /* Start the Loop */ ?> | |
<?php while ( have_posts() ) : the_post(); ?> | |
<?php | |
// check whether we have the counter and whether it's below 2 (for the first 2 posts) | |
if ( isset($counter) && $counter < 2 ): | |
// I always use get_template_part to get a template file to work on the content | |
// makes loops a lot easier to manage. This line will get the file content-normal.php | |
// in there you can do everything you do normally when inside the loop... | |
get_template_part( 'content', 'highlight' ); | |
$counter++; | |
else: | |
get_template_part( 'content', 'normal' ); | |
endif; | |
?> | |
<?php endwhile; ?> | |
<?php else : ?> | |
<p><?php _e( 'Error message: no posts found...', 'oneltd' ); ?></p> | |
<?php endif; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment