How to group WordPress posts by day

wordpress-insert-date

This is a little trick that I recently used in a design. I had to separate the posts by day, and insert the date once, a bit like what you can see on your likes page on StumbleUpon.

To do it, all you have to do is to insert this little bit of code in your WordPress loop.

if( $current_date != get_the_date(‘F j, Y’) ){
echo ‘<div class=”day”>’.get_the_date(‘F j, Y’).’</div>’;
$current_date = get_the_date(‘F j, Y’);
}