WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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 display posts on index page within a links-list, with only the titles, till now i did the job, but now i want to have space between titles and be separated by day.

Please check wimp.com and see how the titles are separated.

Right now my code is something like this

<?php query_posts($query_string.'&cat=-3');  
    while (have_posts()) : the_post(); ?>

      <span class="date"><?php the_time('M j') ?></span>
<a class="title" href="<?php the_permalink() ?>"><?php the_title(); ?></a>


share|improve this question
up vote 0 down vote accepted

Add a variable to hold the previous post's date, and then add a <br /> or something when it changes.

    $prev_date = ''; // initialize to empty string
    while (have_posts()) : the_post(); ?>
        <?php if( strlen( $prev_date ) > 0 && get_the_time( 'M j' ) != $prev_date ): ?>
            <br /> <!-- or whatever you want to use to separate your date blocks -->
        <?php endif; ?>
        <span class="date"><?php the_time('M j') ?></span> - 
        <a class="title" href="<?php the_permalink() ?>"><?php the_title(); ?></a>
        <?php $prev_date = get_the_time( 'M j' );
<!-- continue on with The Loop -->
    <?php endwhile; ?>
share|improve this answer
you are close, but something is not right because now the list is something like this: – Robert Ramsey Apr 4 '13 at 0:40
i.imgur.com/ZdRnd21.gif – Robert Ramsey Apr 4 '13 at 0:47
Whoops. I've fixed the code sample; now the <br /> will happen before the post gets output, so if there needs to be a break, there will be. Also added a check so that there won't be a spurious <br /> at the top of the list. – Pat J Apr 4 '13 at 3:54
Thanks!!! Is working! – Robert Ramsey Apr 4 '13 at 23:15

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.