My dodgy code to get my original question to work.
NB. This is probably wrong on many levels, but it's a start! And if you can improve it, go ahead :) And it probably breaks with pagination.
class ArticleHolder extends Page {
...
function Articles(){
$data = $this->Children();
$data->sort('Date');
return $data;
}
function getDates(){
static $dates;
if (!isset($dates)) {
$data = $this->Children();
$data->sort('Date');
$dates = array();
for ($i = 0; $i < $data->TotalItems(); $i++){
$date = $data->Current()->getField('Date');
$dates[$i] = strtotime($date);
$data->next();
} // end for loop
} // end !isset($dates)
return $dates;
} // end function getDates()
function printDate(){
static $a = 0;
$dateArray = $this->getDates();
$print = true;
if ($a > 0) {
if ($dateArray[$a] == $dateArray[$a-1])
$print = false;
}
$a++;
return $print;
}
function endDate(){
static $a = 0;
$dateArray = $this->getDates();
$print = true;
if ($a < count($dateArray)) {
if ($dateArray[$a] == $dateArray[$a+1])
$print = false;
}
$a++;
return $print;
}
}
ArticleHolder.ss
<div id="Content" class="typography">
$Content
<% control Articles %>
<% if Parent.printDate %><div class="date"><h2 class="newsDateTitle">$Date.Nice</h2><% end_if %>
<div class="newsArticle">
<h3 class="newsDateTitle"><a href="$Link" title="Read more on "{$Title}"">$Title</a></h3>
<p class="newsSummary">$Content.FirstParagraph <a href="$Link" title="Read more on "{$Title}"">Read more >></a></p>
<% if Parent.endDate %></div><!-- end of div.newsArticle --><% end_if %>
</div>
<% end_control %>
</ul>
</div>