Support » Themes and Templates » show post dates, but list year only once?

  • Hi, this has been driving me crazy, maybe someone here has done this before?

    I want to list my posts and show the date. But I only want the year to show in the top post of that year. The latest post in 2008 would read December 2008, but the following ones would read only July, March, January — No year. Then December 2007, followed by only July, March, etc etc.

    I’ve tried a bunch of ways to accomplish this, but nothing seems to work. Any suggestions?


Viewing 3 replies - 1 through 3 (of 3 total)
  • Try this. Example is a loop so you may have to wedge this into your existing code:

    while (have_posts()) : the_post();
    if (mysql2date("Y", $post->post_date) != $year) {
    $year = mysql2date("Y", $post->post_date);
    if ($count == 1) {
    the_time('F Y');
    } else {


    woah thanks! that worked nicely

    Actually, I take that back. On my computer it looks fine. On my coworker’s PC the post content does not show up (or on my mac when i use my Firebug firefoxplugin on the page).
    The dates show up but the content won’t. I was hoping this wouldn’t be too complicated for a browser to handle. (this is the first of three loops on a page)

    Can anyone tell what I’m doing wrong?

    <div class="hr"><hr /></div>
    <a name="timeline"></a>
    <div class="presspost" valign="top" id="post-<?php the_ID(); ?>">
    <div class="pressentry">
    <p class="about_caption2"><a name="Timeline"></a>Company History</p>
    <table class="timeline" border="0">
    <?php $my_query = new WP_Query('category_name=timeline&showposts');
    while ($my_query->have_posts()) : $my_query->the_post(); ?>
    <td class="namendate3" width="34">
    <?php if (mysql2date("Y", $post->post_date) != $year) {
    $year = mysql2date("Y", $post->post_date);
    } if ($count == 1) {echo "<br />"; the_time('Y');} $count++; ?>
    <td class="namendate2">
    <?php the_time('M') ?>
    <?php the_content('<p class="serif">Read the rest of this page &raquo;</p>'); ?>
    <?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
    <?php endwhile; ?>
    <br />
    <br />
    <p align="right"><a href="#top">back to top</a></p>
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘show post dates, but list year only once?’ is closed to new replies.