Skip to content

Instantly share code, notes, and snippets.

@micahwave
Created May 7, 2012 17:28
Show Gist options
  • Select an option

  • Save micahwave/2629127 to your computer and use it in GitHub Desktop.

Select an option

Save micahwave/2629127 to your computer and use it in GitHub Desktop.
wp_query, first post, last post
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