WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Customizing date display (3 posts)

  1. Aen
    Member
    Posted 4 years ago #

    I want to display month only in the last post of the month and every post to have the day. LIke:

    Feb 19: Title
    12: Title
    05: Title
    01: Title
    Mar 23: Title
    17: Title
    so on...

    Any ideas?

  2. MichaelH
    Member
    Posted 4 years ago #

    Before your loop put this:

    <?php
    $last_date='';
    ?>

    Then inside your loop put

    <?php
    $current_post_ym = get_the_time('Ym');
    if ( $last_date != $current_post_ym ) {
      $last_date = $current_post_ym;
      $display_date = get_the_time('M d');
    } else {
      $display_date = get_the_time('d');
    }
    ?>
    <p><?php echo $display_date .':'; ?> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
  3. Aen
    Member
    Posted 4 years ago #

    Works great! Thanks Michael!

Topic Closed

This topic has been closed to new replies.

About this Topic