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


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; ?>
| 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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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