One of the basic features of most blog packages is breaking up lists of posts by the day they were posted on. Instead of listing the post-date on EVERY node teaser, they're displayed like so:

TUESDAY, DECEMBER 13th
> Node 1
> Node 2
> Node 3
MONDAY, DECEMBER 12th
> Node 4
> Node 5
> Node 6

And so on. Quite a few multi-user sites like metafilter.com display things this way, too. Is there a simple way to do this using PHPTemplate theming? I'm sure I'm missing something obvious...

Comments

lzfranc’s picture

or showing in this condition?

DECEMBER
> Node1
> Node2
> Node3

NOVEMBER
> Node 4
> Node 5 ...

venkat-rk’s picture

The Node Queue module does list nodes by group, but I am not sure it meets your exact requirement:
http://drupal.org/node/38678

merlinofchaos’s picture

No, Node Queue won't do it.

Views can if you write a custom theme for the view.

-- Merlin

[Point the finger: Assign Blame!]
[Read my writing: ehalseymiles.com]

-- Merlin

[Read my writing: ehalseymiles.com]
[Read my Coding blog: Angry Donuts]

nedjo’s picture

CVS log messages are grouped by date, see

http://drupal.org/cvs

You can see how this is done in the cvs.module.

See use of the _cvs_date() function, which tests each record to see if it has a new date and, if so, outputs the date.

eaton’s picture

That's a really nice compartmentalized function. I pulled it out and tweaked it a bit for easy use in a theme:

function date_header($timestamp, $format = 'F j, Y') {
  static $last;
  $date = format_date($timestamp, 'custom', $format);
  if ($date != $last) {
    $last = $date;
    return $date;
  }
}

If there's a new date, it returns the formatted string. If not, it returns nothing. It would probably be best used in a custom listing; sticking a call to this right in the node.tpl.php would get tricky, as it might show up in all sorts of listings where date-headers would be inappropriate. Thanks, though, for pointing me in the right direction.

--
Jeff Eaton | I heart Drupal.

--
Eaton — Partner at Autogram

C-Watootsi’s picture

Nice one Jeff -- I recently asked about this same issue (also thinking of metafilter) and was just pointed to your code. It's odd that Aggregator has this function by default, but not the "group blog" setup.

ilike’s picture

Hi may anyone tell me where to put the above function for calling later in the template. Just putting it in the template doesnt work since it will be executed once for every node and giving error since the function is already defined.

ilike’s picture

If someone is interested in doing this in drupal 5.7 i found that the following(probably terrible) code works in a template file.

		
		global $forra;
		$datum = format_date($node->created, 'custom', 'F j, Y');
		if ($datum != $forra) {
		print $datum;
		$forra = $datum;
		}