WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to set a group of posts grouped by date as a list. Below is what I would like to have:

    <li><a href="#">Lorem ipsum</a></li>
Previous day...
    <li><a href="#">Lorem ipsum</a></li>
    <li><a href="#">Lorem ipsum</a></li>

I did that:

<?php while (have_posts()) : the_post(); ?>
<?php the_date(); ?>
<li><a href="#"><?php the_time(); ?><?php the_title(); ?></a></li>
<?php endwhile; ?>

I don't really know where to put the < ul > or < /ul > tags. Any idea?

Actually, setting the starting tag is OK by doing this:

<?php the_date('','','<ul>'); ?>

But I can't figure out how to set the closing tag.

Regards, Alex

share|improve this question
up vote 1 down vote accepted

I usually perform a simple check to see if that day has changed.

$day_check = '';
while (have_posts()) : the_post(); 
  $day = get_the_date('j');
  if ($day != $day_check) {
    if ($day_check != '') {
      echo '</ul>'; // close the list here
    echo get_the_date() . '<ul>';
<li><a href="#"><?php the_time(); ?><?php the_title(); ?></a></li>
$day_check = $day;
endwhile; ?>
share|improve this answer
I think there is a mistake :/ It gives me something like this: <ul><li><a href="#">...</a></li> </ul><li><a href="#">...</a></li> The closing UL is wrongly placed :( (and the date is no more displayed). – flintsburg Nov 23 '11 at 16:57
sorry, it was adapted from another file that does something slightly different. I edited the code above. – cbaigorri Nov 23 '11 at 18:20
Thank you. I just had to add </ul> outside the loop to close the last list. Thx :) – flintsburg Nov 23 '11 at 19:13

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.