Group Posts by Date

March 02, 2013

If you publish posts multiple times per day sometimes there is a need to wrap posts by date. This is common amongst lots of link bloggers.

If you run a WordPress driven site thankfully this is super easy with one slight addition inside your loop.

<p><?php the_date(); ?></p>

What the above snippet does is displays or returns the date of a post, or a set of posts if published on the same day.

Below is a basic loop with the the_date(); added.

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

<p><?php the_date(); ?></p>

<div class=“post”>

<h2><?php the_title(); ?></a></h2>

<div class=“entry”> <?php the_content(); ?> </div>

<?php endwhile; else: ?> <p>Sorry, no posts matched your criteria.</p> <?php endif; ?>

More info: