Created
May 7, 2012 17:28
-
-
Save micahwave/2629127 to your computer and use it in GitHub Desktop.
wp_query, first post, last post
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
| function time_first_post() { | |
| global $wp_query; | |
| return ( in_the_loop() && $wp_query->current_post == 0 ); | |
| } | |
| function time_last_post() { | |
| global $wp_query; | |
| return ( in_the_loop() && $wp_query->current_post == $wp_query->post_count-1 ); | |
| } | |
| $query = new WP_Query( $args ); | |
| global $wp_query; | |
| $wp_query = $query; | |
| if( have_posts() ) { | |
| while( have_posts() ) : the_post(); ?> | |
| <?php if( time_first_post() ) : ?> | |
| <h1><?php the_title(); ?></h1> | |
| <?php else : ?> | |
| <h4><?php the_title(); ?></h4> | |
| <?php endif; ?> | |
| <?php endwhile; | |
| } | |
| wp_reset_query(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment