Support » Fixing WordPress » show year if not current

  • Resolved superultra

    (@superultra)


    Is there a way to basically do this in the loop:
    If the post was created in the current year, do not display the year. Otherwise, display the year.

    In other words, if they are reading posts from 2005 and it is 2005, it will not show 2005. But if they go into the archives, it will show the year.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Something like this, perhaps?
    <?php
    // this should be in the loop
    $post_year = mysql2date('Y', $post->post_date);
    $this_year = date('Y');
    if ($post_year != $this_year) {
    echo $post_year;
    }

    Suppressing the year for current-year posts is left as an exercise to the reader.

    Thread Starter superultra

    (@superultra)

    Great. That did the trick. Many thanks Skippy.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘show year if not current’ is closed to new replies.