Skip to content

Instantly share code, notes, and snippets.

@jnowland
Created May 5, 2013 08:21
Show Gist options
  • Save jnowland/5520111 to your computer and use it in GitHub Desktop.
Save jnowland/5520111 to your computer and use it in GitHub Desktop.
<?php /* making sure we 'orderby' correctly */
query_posts( $query_string . '&orderby=date&order=DEC' ); ?>
<?php if ( have_posts() ) : ?>
<?php
/* Setup */
$display_year = '';
$format = 'd/m/Y';
$year_position = 2;
?>
<?php while( have_posts() ) : the_post(); ?>
<?php /* Display a new date if we get to one */
$post_date = explode( '/', get_the_date($format) );
$post_year = $post_date[$year_position];
if ( $display_year == '' )
{
echo '<div class="year year-'.$post_year.'"><time class="date-title">'.$post_year.'</time>';
$display_year = $post_year;
}
elseif ( $post_year != $display_year )
{
echo '</div><!--close div--><div class="year year-'.$post_year.'"><time class="date-title">'.$post_year.'</time>';
$display_year = $post_year;
}
?>
<?php /* output other junk as normal, for example: */ ?>
<article>
<h3>
<a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>">
<?php the_title(); ?>
</a>
</h3>
<time datetime="<?php echo get_the_date(j-S-F); ?>"><?php echo get_the_date(j-S); ?></time>
</article>
<?php endwhile; ?>
</div><!-- closes last div-->
<?php endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment