Group Posts by Date

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: codex.wordpress.org

This post currently has no responses. What do you think?

You can use basic HTML when posting code, please turn all < characters into &lt; or > into &gt;
If the code is multi-line, use <pre><code></code></pre>

Leave a Reply

Your email address will not be published. Required fields are marked *

Current ye@r *